Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
Hi all,

Im finding some little issues when a users opens my app the first time and still has to accept the remote notifications.
My app will store the token of the user in a public string of the AppDelegate

However, when the user takes a while for accepting it, the app is already in its main viewcontroller. By then the app still didnt fetched the token. Once the user closed the app fully and opens it again, it did fetched the token and it can be stored on my host.

Anyone understand my problem and how to fix this?
Is there some kind of 'listener' I can set up that will be triggered once the app received an token?

Thanks!
 

Boris-VTR

macrumors regular
Apr 18, 2013
247
17
I would use something like Local Notifications. When user receives token, app would create and send notification witch custom name. Then you could create notifications listener that would react to that notification.

When user receives token you create local notification:
Code:
NSNotification *notification = [NSNotification      notificationWithName:recievedToken 
     object:self
     userInfo: @"whatever data you save"];

[[NSNotificationCenter defaultCenter] postNotification:notification];

Then set up listener to this notification:
Code:
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver: self
           selector: @selector(handleNotification)
           name: notification
           object:[[UIApplication sharedApplication] delegate)];

-(void) handleNotification
{
    // Handle notification code here...
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.