我的项目(在Xamarin.iOS中构建)使用UserNotifications
。在iOS 8.0之后可以正常工作。但是,DidReceiveRemoteNotification
方法未在收到通知时在同事的iPhone(iOS 8.4.1)上调用。我认为它与代码无关,也许我错过了一些操作,例如在iOS 9之前的Info.plist有什么建议吗?
UNUserNotificationCenter center = UNUserNotificationCenter.Current;
center.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Badge, (bool arg1, NSError arg2) =>
{
});
center.Delegate = new NotificationDelegate();
我在方法FinishedLaunching
中注册了NotificationCenter。它在模拟器和某些iPhone(iOS10.3和iOS 12.0)中均可正常运行
答案 0 :(得分:0)
尝试使用以下代码
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
UNUserNotificationCenter center = UNUserNotificationCenter.Current;
center.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Badge, (bool arg1, NSError arg2) =>
{
});
center.Delegate = new NotificationDelegate();
}
else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
}