1

我正在尝试在我的应用程序中使用远程推送通知,并且我试图在我的应用程序中进行此测试,但是在我一开始点击“允许”后我无法重置警报弹出窗口。

所以我的问题是:

即使用户在警报弹出窗口中点击“不允许”,我仍然可以获得设备令牌吗?

4

3 回答 3

3

使用 appDelegate 方法

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        self.mDeviceToken = deviceToken;

        //Removing the brackets from the device token
        NSString *tokenString = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];

        NSLog(@"Push Notification tokenstring is %@",tokenString);

    }   

万一出错

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{

    NSString* s=[[NSString alloc] initWithFormat:@"%@",error];
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:s delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [s release];
// lert because your device will not show log
}
于 2012-05-09T07:01:30.263 回答
0

使用以下委托方法...

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{

    NSLog(@">>%@",deviceToken);// this will give  you token
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{

    NSLog(@">>%@",error); // this will gave you error msg with description.

}

希望对你有帮助..

于 2012-05-09T07:01:41.030 回答
0
-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

{

    NSLog(@"My token is: %@", deviceToken);

}

这样你就得到了 iPhone 设备令牌

于 2012-05-09T07:17:32.443 回答