gpt4 book ai didi

ios - iOS9.3.5如何注册自定义推送通知?

转载 作者:行者123 更新时间:2023-11-29 00:23:29 24 4
gpt4 key购买 nike

这就是我的应用程序注册推送通知的方式。

@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;
}

运行应用程序时,我会回显设备 token 以确保是什么。

enter image description here

在运行 7.1.2 (11D257) 的 iPhone 上测试 6.1 版本时,应用程序可以正常注册通知,并在用户上传图片时回显设备 token 。但是当我在 iPad 版本 9.3.5 (13G36) 上运行它时,XCode 控制台显示 registerForRemoteNotificationTypes: iOS 8.0 及更高版本不支持。 并且上传到 iPad 的图片仅显示 0,其中设备 token 应该是。

最佳答案

尝试一下:

   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)];
}

希望对你有帮助。

关于ios - iOS9.3.5如何注册自定义推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43690303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com