简体   繁体   English

读取iPhone推送通知的设备令牌

[英]Read Device Token for iPhone Push Notification

I try to implement push notification in my iPhone application. 我尝试在我的iPhone应用程序中实现推送通知。 I have create Provisioning Profile and App-id for push notification and add this certificates into Xcode. 我创建了用于推送通知的Provisioning Profile和App-id,并将此证书添加到Xcode中。 Connect iPhone device to mac system and build application through device for read Device token using the following code. 使用以下代码将iPhone设备连接到mac系统,并通过设备构建应用程序以读取设备令牌。

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken:\n%@", deviceToken);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    NSLog(@"didFailToRegisterForRemoteNotificationsWithError:%@", [error localizedDescription]);
}

But it returns error.. like 但它返回错误..像

didFailToRegisterForRemoteNotificationsWithError:no valid 'aps-environment' entitlement string found for application 2012-07-18 14:18:08.597 Z2NotifyMe[1874:707] didFailToRegisterForRemoteNotificationsWithError:Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x11fee0 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application} didFailToRegisterForRemoteNotificationsWithError:未找到适用于应用程序的有效“ aps环境”权利字符串2012-07-18 14:18:08.597 Z2NotifyMe [1874:707] didFailToRegisterForRemoteNotificationsWithError:Error Domain = NSCocoaErrorDomain Code = 3000“未找到有效的“ aps环境字符串”权利适用于应用程序” UserInfo = 0x11fee0 {NSLocalizedDescription =找不到适用于应用程序的有效“ aps-environment”权利字符串}

I have remove all old certificates in Xcode and my device, then re-create all certificate newly then execute above same code it returns same above error. 我已经删除了Xcode和设备中的所有旧证书,然后重新创建了所有证书,然后执行相同的代码,并返回相同的错误。

Please help solve this problem. 请帮助解决此问题。

Thanks.. 谢谢..

Register your device using the following code : 使用以下代码注册设备:

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

In the applicationDidFinishLaunching: method. applicationDidFinishLaunching:方法中。

I hope that the device on which you are trying is not Jailbroken. 我希望您尝试使用的设备没有越狱。

I had a similar problem when I did all the steps correctly but i still got this error. 当我正确执行所有步骤时,我遇到了类似的问题,但仍然出现此错误。

Try doing the following steps, it helped me: 尝试执行以下步骤,对我有帮助:
1) Go to you Provisioning Profile -> Provisioning 1)转到您的Provisioning Profile-> Provisioning
2) Press the "edit" button in the right hand side near your app provisioning profile - > then modify 2)按下右侧应用配置文件旁边的“编辑”按钮->然后进行修改
3) Make some change here, it doesn't really matter what the change is, this is just to trigger a new profile. 3)在此处进行一些更改,更改实际上并不重要,这只是触发一个新的配置文件。 Unselect one of the devices, or change the name, you can change it back later. 取消选择其中一台设备,或更改名称,稍后可以将其更改回。
4) press the "submit" button 4)按“提交”按钮
5) download the profile and drag it to Xcode. 5)下载配置文件并将其拖动到Xcode。 (delete your old profile in Xcode before) (之前请在Xcode中删除您的旧个人资料)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM