2012-01-21 2 views
1

Comment puis-je obtenir le jeton de périphérique? J'essaie de l'ajouter et je n'arrive pas à comprendre. Que dois-je faire? Où vais-je? De quoi ai-je besoin pour obtenir ceci?Notifications push de jeton de périphérique

- (void)application:(UIApplication *)application 
     didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken 
{ 
    // Tell Parse about the device token. 
    [PFPush storeDeviceToken:newDeviceToken]; 
    // Subscribe to the global broadcast channel. 
    [PFPush subscribeToChannelInBackground:@""]; 
} 

Répondre

1

Vous appelez registerForRemoteNotificationTypes: lorsque vos lancements d'applications, le système appelle de nouveau dans votre application via la méthode application:didRegisterForRemoteNotificationsWithDeviceToken: (que vous devez mettre en œuvre). La variable newDeviceToken aura le jeton de périphérique.

Voir la documentation de la classe UIApplication.

5
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken { 
    // Get a hex string from the device token with no spaces or < > 

    NSString *deviceToken = [[[[_deviceToken description] 
        stringByReplacingOccurrencesOfString: @"<" withString: @""] 
        stringByReplacingOccurrencesOfString: @">" withString: @""] 
        stringByReplacingOccurrencesOfString: @" " withString: @""]; 



} 
1

Vous devez appeler ceci dans le délégué de l'application.

[[UIApplication sharedApplication] 
registerForRemoteNotificationTypes: 
    (UIRemoteNotificationTypeBadge | 
    UIRemoteNotificationTypeSound | 
    UIRemoteNotificationTypeAlert)]; 

Assurez-vous de l'application délégué a cette fonction

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken { 
// Get a hex string from the device token with no spaces or < > 

NSString *deviceToken = [[[[_deviceToken description] 
       stringByReplacingOccurrencesOfString: @"<" withString: @""] 
       stringByReplacingOccurrencesOfString: @">" withString: @""] 
       stringByReplacingOccurrencesOfString: @" " withString: @""]; 

}