推送通知委托方法问题 [英] Push notification delegate method issue
本文介绍了推送通知委托方法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Objective C 的新手.在我的应用程序中,我需要实现推送通知,我已经创建了新的应用程序 ID,并且还创建了新的配置文件.我已经完成了这个 link
我已经在我的 appDelegate .m 文件中声明了这个委托函数.
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {NSString *deviceTokens = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];deviceTokens = [deviceTokens stringByReplacingOccurrencesOfString:@" " withString:@""];NSLog(@"注册的设备令牌%@", deviceTokens);self.deviceToken = deviceTokens;}- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {NSString *str = [NSString stringWithFormat: @"Error: %@", err];NSLog(@"字符串 %@",str);}- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {for(userInfo 中的 id 键){NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);}}
但是这个委托函数没有被调用.请帮我解决这个问题.
解决方案
在你的 AppDelegated didfinishLaunching with options 中写下一行
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
I am new to Objective C. In my app i need to implement push notification, i have created new app ID and i have created new provisioning profile also. i have finished all the steps mentioned in this link
i have declared this delegate function in my appDelegate .m file.
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *deviceTokens = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
deviceTokens = [deviceTokens stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"registered device token %@", deviceTokens);
self.deviceToken = deviceTokens;
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"String %@",str);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}
}
But this delegate functions are not called. please help me to fix this issue.
解决方案
In your AppDelegated didfinishLaunching with options write the following line
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
这篇关于推送通知委托方法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文