iOS9.3.5如何注册自定义推送通知?
Posted
技术标签:
【中文标题】iOS9.3.5如何注册自定义推送通知?【英文标题】:How to register for custom push notifications in iOS9.3.5? 【发布时间】:2017-04-28 23:46:35 【问题描述】:这就是我的应用注册推送通知的方式。
@implementation AppDelegate
//REGISTER FOR THE NOTIFICATIONS TYPES
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
//-- Set Notification
if ([application
respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
// ios 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
else
// iOS < 8 Notifications
_storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
_storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];
if (launchOptions != nil)
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
NSLog(@"Launched from push notification: %@", dictionary);
/*[self addMessageFromRemoteNotification:dictionary updateUI:NO];*/
return YES;
运行应用程序时,我会回显设备令牌以确保是什么。
在运行 7.1.2 (11D257) 的 iPhone 上测试 6.1 版本时,该应用程序会很好地注册通知,并在用户上传图片时回显设备令牌。但是当我在 iPad 版本 9.3.5 (13G36) 上运行它时,XCode 控制台显示 registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.
并且上传到 iPad 的图片只显示设备令牌应该在的位置为 0。
【问题讨论】:
【参考方案1】:试试看:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
希望对你有帮助。
【讨论】:
以上是关于iOS9.3.5如何注册自定义推送通知?的主要内容,如果未能解决你的问题,请参考以下文章