2017-08-29 71 views
4

我試圖找出用戶是否在iOS設置中的通知中有聲音/振動。我使用Xamarin格式,但Xamarin.iOS也可以接受。Xamarin iOS:檢查是否啓用通知聲音

它看起來像是類似 UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Sound,new NSSet()); 但我不確定如何處理NSSet以讀取設置。

回答

4

在iOS 10中添加了UserNotifications.framework,並將其替換爲UIUserNotification

您可以使用UNUserNotificationCenter決定啓用什麼:

var notificationSettings = await UNUserNotificationCenter.Current.GetNotificationSettingsAsync(); 
switch (notificationSettings.SoundSetting) 
{ 
    case UNNotificationSetting.Disabled: 
     break; 
    case UNNotificationSetting.Enabled: 
     break; 
    case UNNotificationSetting.NotSupported; // Simulator... 
     break; 
} 
+0

該代碼會拋出異常低於10,所以一定要抓住它的任何iOS版! – m4tt1mus