我正在尝试检查我的应用程序的 PushNotifications 是否已启用。
在 AppDelegate.m 中,我为远程通知注册了应用程序,并在 iPhone (iOS 8) 上的设置中启用了此应用程序的推送通知。
我已经用谷歌搜索了方法:
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
BOOL check = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
结果,types = UIRemoteNotificationTypeNone 和 check = NO。
我正在使用 code sample注册推送通知申请:
- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary*)launchOptions
{
//-- Set Notification
if ([application respondsToSelectorselector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypesUIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
//--- your custom code
return YES;
}
这里有什么问题?
我认为您已经找到了解决方案,但以防万一:在 iOS 8 中,已弃用 enabledRemoteNoficationTypes 您应该使用:
if ([[UIApplication sharedApplication] respondsToSelectorselector(currentUserNotificationSettings)]) {
UIUserNotificationSettings *currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (currentSettings.types == UIUserNotificationTypeNone) {}
最好的
关于IOS 8 推送通知检查返回错误的 UIRemoteNotificationType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26379579/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |