2015-04-27 118 views
0

当iPhone应用程序完全关闭时,即使不在后台,也可以如何处理APNS处理。 例如应用程序完全关闭时,将APNS数据存储在sqlite中。推送通知的后台处理

+0

http://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the- background-if-it-was-force-quit-by-the-user试试这个...... – vijeesh

回答

1

中的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]; 
} 
在所有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 
}