gpt4 book ai didi

iphone - didRegisterForRemoteNotificationsWithDeviceToken : doesn't invoke on calling registerForRemoteNotificationTypes:?

转载 作者:行者123 更新时间:2023-12-03 18:30:23 27 4
gpt4 key购买 nike

我正在 navBased 应用程序中处理推送通知。在 AppDelegate.m didRegisterForRemoteNotificationsWithDeviceToken: 调用 registerForRemoteNotificationTypes 时不会调用:代码如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

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

[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];

return YES;
}



- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Get a hex string from the device token with no spaces or < >
NSLog(@"applicationDidFinishLaunchingWithOptions dev token test");

NSString *deviceTokenStr = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];

NSLog(@"Device Token: %@", deviceTokenStr);
}

我很确定配置文件不是问题。我发现错误:

注册时出错。错误:错误域=NSCocoaErrorDomain代码=3000“找不到应用程序的有效'aps-environment'权利字符串”UserInfo=0x115490 {NSLocalizedDescription=没有找到应用程序的有效'aps-environment'权利字符串}

谁能告诉我这段代码发生了什么并且它不起作用?谢谢

最佳答案

在 Appdelegate didFinishLaunching 方法中输入此代码 -

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

然后将这两个方法复制并粘贴到同一个 appdelegate 中 -

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);
NSString *dToken = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
dToken = [dToken stringByReplacingOccurrencesOfString:@" " withString:@""];


NSLog(@"STR%@",dToken);


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

NSLog(@"Failed to get token, error: %@", error);
}

关于iphone - didRegisterForRemoteNotificationsWithDeviceToken : doesn't invoke on calling registerForRemoteNotificationTypes:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4994302/

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