7

我将用户名、密码和设备令牌的值发布到 .net 网络服务。但它没有获得任何设备令牌值。我正在使用下面的代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert ]; 
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{    
   NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: %@", deviceToken); 
   NSString *dt = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; 
   dt = [dt stringByReplacingOccurrencesOfString:@" " withString:@""]; 
   self.DeviceToken=dt; 
   NSLog(@"~~~~devToken(dv)=%@",deviceToken);
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{      
    NSLog(@"Failed to get token, error: %@", error);
}

但在控制台中它显示

获取令牌失败,错误:错误域 = NSCocoaErrorDomain 代码 = 3000 “找不到应用程序的有效 'aps-environment' 权利字符串” UserInfo=0x1a0810 {NSLocalizedDescription=找不到应用程序的有效 'aps-environment' 权利字符串

任何的想法?提前致谢!

4

4 回答 4

2

您是否在临时文件中启用了推送通知?

浏览教程以检查您是否做对了

首先尝试从您的 Mac 向设备发送推送通知,如教程中所述。您将需要一个服务器端的 pem 文件,您需要从 iOS 门户创建该文件 :)

于 2012-10-11T19:36:00.873 回答
1

我假设您正在设备上运行/调试,因为您在尝试从模拟器注册推送令牌时会遇到不同的错误。只是想摆脱它。

话虽如此,通常导致您看到的错误是您选择的配置文件中未启用推送通知。现在,您可能已经进入 iOS 配置门户并为您的 App ID 启用了推送(还要注意是否为您的开发或分发配置文件启用了推送)。但是,在这样做之后,您必须进入并“弄脏”供应门户的供应配置文件,以生成一个包含推送权利的新供应配置文件。

通过“弄脏”它,我的意思是进入并更改配置文件的某些设置以强制重新创建。如果当您返回配置文件列表时,状态会暂时更改为“待处理”几秒钟,然后再次变为“活动”并允许您下载它,您就会知道您是否“弄脏”了它。

哦,我刚刚发现这个也回答了这个问题(如果我把它链接错了,请有人帮忙):Bundle Identifier and push certificate... aps-environment entitlement error

于 2012-10-11T19:32:33.277 回答
0
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{    
   NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: %@", deviceToken); 
   NSString *dt = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; 
   dt = [dt stringByReplacingOccurrencesOfString:@" " withString:@""]; 
   self.DeviceToken=dt; 

}
于 2013-04-12T07:14:35.747 回答
0

要获取设备令牌,请在设备中运行应用程序

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Let the device know we want to receive push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
        (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    return YES;
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"My token is: %@", deviceToken);
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}
于 2014-10-22T11:06:56.927 回答