2015-04-27 3 views
0

Когда приложение iPhone закрыто полностью, то есть даже не в фоновом режиме, то как можно обрабатывать APNS. , например. Храните данные APNS в sqlite, когда приложение полностью закрыто.Фоновая обработка Push Notification

+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]; 
} 

во всех ВК:

- (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 
}