gpt4 book ai didi

iOS registerForRemoteNotifications 不会生成错误但不会触发提供设备 token 的委托(delegate)

转载 作者:行者123 更新时间:2023-12-01 15:50:43 24 4
gpt4 key购买 nike

<分区>

直到今天早上一切正常,我需要设备 token 才能继续当我在 iOS 设备上调试时,didRegisterForRemoteNotificationsWithDeviceTokendidFailToRegisterForRemoteNotificationsWithError 方法都不会被触发。我真的很感激一些帮助。我的代码如下。

        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){

UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];

[application registerUserNotificationSettings:mySettings];
//[application registerForRemoteNotifications];


}else{
[application registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: %@", deviceToken);
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSString *deviceID = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
deviceID = [deviceID stringByReplacingOccurrencesOfString:@" " withString:@""];

NSLog(@"Device_Token -----> %@\n",deviceID);
[[NSUserDefaults standardUserDefaults] setObject:deviceID forKey:@"KiviDeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Error: %@", error.description);

if (error.code == 3010) {
NSLog(@"Push notifications are not supported in the iOS Simulator.");
} else {
NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
}
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
NSLog(@"NotificationSettings: %@", notificationSettings);
//register to receive notifications
[application registerForRemoteNotifications];
}

我检查过iOS 设置应用程序通知已启用,不会调用该方法

我需要一些关于“排除推送通知故障”的帮助“如果既没有委托(delegate)回调应用程序:didRegisterForRemoteNotificationsWithDeviceToken:也没有应用程序:didFailToRegisterForRemoteNotificationsWithError:被调用,NotificationSettings 正在获取我认为回调不是调用,因为连接尚未建立。”

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