我正在使用 Azure 通知中心实施推送通知。到目前为止,只要通知按预期出现,它就可以正常工作,但没有声音(是的,我检查过以确保我的手机没有处于静音状态;)。
我的代码:
通知 json: {“aps”:{“alert”:“通知中心测试通知”},“声音”:“默认”}
AppDelegate.cs:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
// Other initialization code here...
UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (approved, err) => {
// Handle approval
if (approved)
{
}
});
UIApplication.SharedApplication.RegisterForRemoteNotifications();
// Watch for notifications while the app is active
UNUserNotificationCenter.Current.Delegate = new NotificationDelegate();
return base.FinishedLaunching(app, options);
}
NotificationDelegate.cs:
public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
if (UIDevice.CurrentDevice.CheckSystemVersion(14, 0))
{
completionHandler(UNNotificationPresentationOptions.List | UNNotificationPresentationOptions.Banner | UNNotificationPresentationOptions.Sound);
}
else
completionHandler(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Sound);
}
还有什么遗漏吗?
您可以尝试在AppDelegate.cs中注册
RegisterUserNotificationSettings
。
var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);
希望有帮助!