简体   繁体   English

推送通知的后台处理

[英]Background handling of Push Notification

When iPhone app is closed totally ie not even in background, then how APNS handling can be done. 当iPhone应用程序完全关闭(即甚至不在后台)时,如何完成APNS处理。 eg Store APNS Data in sqlite when app is completely closed. 例如,当应用程序完全关闭时,在sqlite中存储APNS数据。

in AppDelegate: 在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: 在所有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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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