Ric*_*ker 17 iphone apple-push-notifications devicetoken ios appdelegate
我正在开发一个需要推送通知的iPhone应用程序.我按照说明创建了认证并修改了应用ID.我并不完全确定我这样做是正确的,但我的确遵循了指示.知道如何检查这是否正常?
当我在模拟器中运行时,我收到一条错误消息,指出模拟器不支持推送通知.这有点预期.
顺便说一下:我有几次看似这个问题.它总是似乎是一个破牢的手机.我的手机没有被囚禁.
但是当我在iPhone上调试时,didRegisterForRemoteNotificationsWithDeviceToken方法永远不会被触发.我真的很感激一些帮助.我的代码如下.
-(void)applicationDidFinishLaunching:(UIApplication *)application
{
rootController.delegate = self;
[window addSubview:rootController.view];
[window makeKeyAndVisible];
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *str =
[NSString stringWithFormat:@"%@",deviceToken];
NSLog(str);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(str);
}
Run Code Online (Sandbox Code Playgroud)
Pat*_*ley 21
通常,如果didRegisterForRemoteNotificationsWithDeviceToken从未调用过,那是因为您使用的配置文件不是APS-entitled.如果您的应用程序是生产应用程序,则必须使用分发配置文件对其进行签名才能推送.如果它是开发应用程序,则必须使用开发配置文件对其进行签名.
编辑:值得注意的是provisioning profile必须使用显式的bundle id.发送到使用通配符配置文件签名的任何内容都将无法发送.
我遇到过同样的问题.
对我来说,应用程序的通知设置已关闭所有内容.
如果在iOS设置中禁用了应用程序通知,则不会调用该方法.
一旦我打开通知类型,它就开始工作了.
Settings App->Notification Settings->[My App]
| 归档时间: |
|
| 查看次数: |
23472 次 |
| 最近记录: |