Question

In my application i am going to use pushNotification. So in that case how can i use device tokens in different ways?

Let me elaborate more on this side.

Whenever i run my application at that time Device token will be generated,if i go for running the application again and again in the same device than it will generate the same device token or not?

if it will generate the different Device tokens than as per the Apple Documentation how is it Handling at the server side.? what is exactly needed to send from client side (i.e. Device token or other parameters) to the server side and which type of scenario is having at the server side for the same?

if anybody having any solution or any code snippet or any useful link,which would be appreciated.

Was it helpful?

Solution

Here is an example, not necessarily working code:

- (void)sendProviderDeviceToken:(NSString *)tokenString {
    NSString *udid = [[UIDevice currentDevice] uniqueIdentifier];

    NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
    UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

    NSString *data = [NSString stringWithFormat:@"udid=%@&token=%@&id=%@&type=%i", udid, tokenString, bundleID, type];
    NSString *escapedData = [[data description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSString *httpRequestURLString = [NSString stringWithFormat:@"http://%@/RegisterDevice.cgi?%@", kRegistrationURI, escapedData];
    NSURL    *httpRequestURL       = [NSURL URLWithString:httpRequestURLString];
}

OTHER TIPS

Mishal, per your comment on CocoaFu's answer

I mean whenever i launch my application at that time it will generate the different tokens for that device or not? And if it generates the different tokens than how to handle it in the proper way?

This paragraph in the iOS doc is helpful in understanding when device tokens can change on a user's device, and why you fire it every time the app launches:

By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device. If a user restores a backup to a device other than the one that the backup was created for (for example, the user migrates data to a new device), he or she must launch the application at least once for it to receive notifications again. If the user restores backup data to a new device or reinstalls the operating system, the device token changes. Moreover, never cache a device token and give that to your provider; always get the token from the system whenever you need it. If your application has previously registered, calling registerForRemoteNotificationTypes: results in iOS passing the device token to the delegate immediately without incurring additional overhead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top