Question

I'm developing a library for mobile apps. The library is mainly a wrapper to my web API (REST), and provide several objects in order to facilitate the implementation in code.

  1. Can my library register to get notifications in behalf of the host app (using APN or GCM)?

    1.1. I believe I can provide a method to do the registration process, but - what if the application is already registered to one of those services?

  2. Can application register to the service more than once?

Was it helpful?

Solution

I can answer on your questions for APN:

For registration to APN use:

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

For unregistering from APN use:

[[UIApplication sharedApplication] unregisterForRemoteNotifications];

Answers on you questions:

  1. Yes. You can register to APN from lib. But you can't receive deviceToken from lib. It would be delegated in method in main app:

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

  2. You could call register method several times. As result delegate method would be called the same number of times. Device token would be the same. But it is not good solution to call register method several times in a row. If want to know if app has already registered for receiving APN you should save device token and then check if it's already exists.

  3. You can call register and unregister methods unlimited number of times.

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