gpt4 book ai didi

ios - 在 Xcode 8 中未调用 didRegisterForRemoteNotificationsWithDeviceToken

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:55:30 26 4
gpt4 key购买 nike

我使用 iOS 10 SDK 在 Xcode 8 上构建我的应用程序。didRegisterForRemoteNotificationsWithDeviceToken 不会为 iOS 9.3 设备调用,因此 iOS 9.3 和以下设备无法接收推送通知。但 iOS 10 设备可以接收推送。如果我使用 iOS 9.3 SDK 在 Xcode 7.3 上构建相同的应用程序,则 iOS 9 设备可以接收推送。所以,我确信我的所有设置都应该是正确的。

这是我的实现:

// Push notification
if( SYSTEM_VERSION_LESS_THAN( @"10.0" ) )
{
if([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];

}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}


}
else
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if( !error )
{
[[UIApplication sharedApplication] registerForRemoteNotifications];
}

}];
}


- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

NSString * tokenAsString = [[[deviceToken description]
stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
stringByReplacingOccurrencesOfString:@" " withString:@""];

}



- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

DLog(@"app didFailToRegisterForRemoteNotificationsWithError: %@", error.description);
}

最佳答案

为什么要使用已弃用的方法?? [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

当我删除它时

[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)categories:nil]];

和使用

[[UIApplication sharedApplication] registerForRemoteNotifications];

我从 APNs 获得了 token 。

关于ios - 在 Xcode 8 中未调用 didRegisterForRemoteNotificationsWithDeviceToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39403752/

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