Push Notification Device Token?

前端 未结 3 915
无人共我
无人共我 2021-01-29 23:12

How to get Device Token from my iPhone Device?

相关标签:
3条回答
  • 2021-01-29 23:40

    This method will show your device token in console.

    - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    
        NSString *str = [NSString 
                         stringWithFormat:@"%@",deviceToken];
        NSString *newString = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
        newString = [newString stringByReplacingOccurrencesOfString:@"<" withString:@""];
        newString = [newString stringByReplacingOccurrencesOfString:@">" withString:@""];
    
    
        [[NSUserDefaults standardUserDefaults] setObject:newString forKey:@"deviceToken"];
    
    
    
        NSLog(@"Your deviceToken ---> %@",newString);
    
    }
    
    0 讨论(0)
  • 2021-01-29 23:42

    If you have implemented this method

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

    for Push Notification then you will get the device token (This method is actually one of the two methods that you require to implement in the application)

    This might find it useful http://urbanairship.com/docs/push.html

    you can also look at Push Notification in Iphone application

    I hope you find this useful.

    0 讨论(0)
  • 2021-01-30 00:00

    this method will print the deviceToken in console in debug mode, if you want to see the device token you can see in UIAlert also.

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
        NSLog(@"APN device token: %@", deviceToken);
        NSString *deviceTokenString = [NSString stringWithFormat:@"%@",deviceToken];
        UIAlertView *deviceTokenAlert = [[UIAlertView alloc] initWithTitle:@"Device Token"
                                                                message:deviceTokenString
                                                               delegate:self
                                                      cancelButtonTitle:@"OK"
                                                      otherButtonTitles:nil];
    
    }
    
    0 讨论(0)
提交回复
热议问题