2012-05-09 162 views
1

我試圖在我的應用程序中使用遠程推送通知,並且我試圖在我的應用程序中進行此測試,但是當我點擊「允許」時,我無法重置警報彈出窗口。如何獲取iPhone設備令牌推送通知?

所以我的問題是:

我仍然獲得設備令牌即使用戶水龍頭在警報彈出「不允許」?

回答

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 
} 
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. 

} 

希望,這將幫助你..

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

{ 

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

} 

通過這種方式,您可以獲得iPhone設備令牌