简体   繁体   中英

Background handling of Push Notification

When iPhone app is closed totally ie not even in background, then how APNS handling can be done. eg Store APNS Data in sqlite when app is completely closed.

in AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    if (launchOptions)
    { //launchOptions is not nil

        NSDictionary *userInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
        userInfoDic = userInfo;

        if (apsInfo)
        { //apsInfo is not nil
            [self performSelector:@selector(postNotificationToPresentPushMessagesVC)
                       withObject:nil
                       afterDelay:1];
        }
    }

    return YES;
}

-(void)postNotificationToPresentPushMessagesVC
{    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"recievePush" object:userInfoDic];
}

in all VC:

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recievePush:) name:@"recievePush"  object:nil];

}

- (void) recievePush : (NSNotification *) notif
{
    NSDictionary *dict = notif.object;

// do something with message data
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM