iOS Apn Device Token
Working with the Roximity platform and wanting to test out the push notification system. For iOS you need to provide a device token to send a test message.
Assuming that you got a valid certificate from Apple, and a provisioning profile for your app, in order to get the token, you need to register your app for notifications.
In your ApplicatonController.m
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self localNotificationPermission];
NSLog(@"Register for push notifications");
[[UIApplication sharedApplication] registerForRemoteNotifications ];
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
return YES;
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *tokenstring = [[[deviceToken description]
stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
stringByReplacingOccurrencesOfString:@" " withString:@""];
// pass tokenstring to your APNS server
NSLog(@"Token is::: %@", tokenstring);
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSString *str = [NSString stringWithFormat:@"Error: %@", error];
NSLog(@"%@", str);
}