1
我正在开发一个具有部署目标iOS 7.1的应用程序。我正在使用Firebase进行推送通知。推送通知在iOS 9设备上正常工作。但不适用于iOS 10设备。如何通过FCM(Firebase)或本机在iOS 10中发送推送通知?
当我搜索时,我发现这个笔记here。
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
} else {
// iOS 10 or later
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
UNAuthorizationOptions authOptions =
UNAuthorizationOptionAlert
| UNAuthorizationOptionSound
| UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter]
requestAuthorizationWithOptions:authOptions
completionHandler:^(BOOL granted, NSError * _Nullable error) {
}
];
// For iOS 10 display notification (sent via APNS)
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
// For iOS 10 data message (sent via FCM)
[[FIRMessaging messaging] setRemoteMessageDelegate:self];
#endif
}
这注:
重要提示:为运行iOS的设备10及以上的,必须将委托对象分配给UNUserNotificationCenter对象,以接收显示通知。
是否需要通过此方法发送推送通知(这是一个新类UNUserNotificationCenter
)?是否可以通过旧的推送通知注册方法?
请让我知道。因此,我需要将我的项目更新到Swift版本2.3或3.0,这需要时间。
是的,它需要时间,你需要更新https://firebase.google.com/docs/cloud-messaging列出的上述方法/ IOS /客户端。这是由于在iOS 10中引入UserNotifications。 –
@iOSCuriosity感谢您的回复。 –
@iOSCuriosity我有同样的问题。我的应用已准备好发布appstore。现在我没有足够的时间将我的应用程序更改为swift 3.有没有解决方案可以在不更新xcode和swift的情况下在ios10设备中接收推送通知? –