2009-08-27 14 views

risposta

7

Se è stato implementato questo metodo

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

} 

per Push Notification allora si otterrà il token dispositivo (questo metodo è in realtà uno dei due metodi di cui avete bisogno per implementare l'applicazione)

Questo potrebbe essere utile http://urbanairship.com/docs/push.html

si può anche guardare Push Notification in Iphone application

spero lo trovi utile

14

questo metodo stamperà il deviceToken in console in modalità di debug, se si vuole vedere il token del dispositivo si può vedere anche in UIAlert.

- (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]; 

} 
+2

Grazie per la risposta! Sai se questo token del dispositivo può cambiare nel tempo, per un iPhone o è costante? – darksider

+1

Ho sempre osservato che il token del dispositivo è costante, ma penso che potrebbe cambiare anche. – User97693321

+1

controllare la risposta di questa domanda http://stackoverflow.com/questions/6927011/is-the-device-token-as-unique-as-the-device-id, dice solo quando si ripristinano i backup il token del dispositivo modificare. – CarmeloS

6

Questo metodo mostrerà il token del dispositivo nella 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); 

}