为什么我的发布应用无法接收 apns 的推送通知,但在开发者版本上可以使用?
我发现发布应用程序无法接收设备令牌。我在我的服务器中找不到设备令牌。但是开发版本可以做到这一点。
这是我的注册码:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir=[paths objectAtIndex:0];
NSFileManager *myFM=[NSFileManager defaultManager];
NSString *filepath = [documentDir stringByAppendingPathComponent:@"devicetoken.plist"];
if([myFM fileExistsAtPath:filepath]==NO){
NSString * str = [NSString stringWithFormat:@"%@",deviceToken];
dic = [[NSMutableDictionary alloc]init];
[dic setObject:[NSString stringWithString:@"DeviceToken"] forKey:@"type"];
[dic setObject:[NSString stringWithString:@""] forKey:@"_id"];
[dic setObject:str forKey:@"token"];
CJSONDeserializer * jo=[[CJSONDataSerializer alloc]autorelease];
NSData *data=[jo serializeDictionary:dic];
NSURL* url=[NSURL URLWithString:[NSString stringWithString:url]];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *contentType = [NSString stringWithFormat:@"application/json"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
[request setHTTPBody:data];
putDoc = [NSURLConnection connectionWithRequest:request delegate:self];
}
I found that the publish app can't receive the device token.I can't find the device token in my server.But the develop version can do this.
This is my register code:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir=[paths objectAtIndex:0];
NSFileManager *myFM=[NSFileManager defaultManager];
NSString *filepath = [documentDir stringByAppendingPathComponent:@"devicetoken.plist"];
if([myFM fileExistsAtPath:filepath]==NO){
NSString * str = [NSString stringWithFormat:@"%@",deviceToken];
dic = [[NSMutableDictionary alloc]init];
[dic setObject:[NSString stringWithString:@"DeviceToken"] forKey:@"type"];
[dic setObject:[NSString stringWithString:@""] forKey:@"_id"];
[dic setObject:str forKey:@"token"];
CJSONDeserializer * jo=[[CJSONDataSerializer alloc]autorelease];
NSData *data=[jo serializeDictionary:dic];
NSURL* url=[NSURL URLWithString:[NSString stringWithString:url]];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *contentType = [NSString stringWithFormat:@"application/json"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
[request setHTTPBody:data];
putDoc = [NSURLConnection connectionWithRequest:request delegate:self];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
记住:
Apple 开发者门户(在配置/应用程序下)中的推送证书必须在应用程序构建和签名之前创建。
所以我会推荐:
->检查配置门户 ->如果正确创建了生产推送证书,则应用程序
->重新构建应用程序商店配置文件
->使用 re-buil prov 重新构建应用程序。文件
->再次上传更新到应用商店
Jonas
Remember:
The push certificate in the Apple Developer Portal (under provisioning / application) must be created before the app built and signed.
So i would recommend:
-> check in the provisioning portal -> application if the production push certificate is proper created
-> re-build the app store provisioning file
-> re-build the app with the re-buil prov. file
-> upload again a update to the app store
Jonas
您还在使用推送通知开发配置文件吗?
如果不是,请将其更改为生产配置文件。
Do you still use the push notification development profile ?
If not, change it to the production profile.