Remote notifications

Discussion in 'iOS Programming' started by DennisBlah, Feb 1, 2015.

  1. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    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!
     
  2. Boris-VTR macrumors regular

    Joined:
    Apr 18, 2013
    #2
    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...
    }
     

Share This Page