0
當iPhone應用程序完全關閉時,即使不在後臺,也可以如何處理APNS處理。 例如應用程序完全關閉時,將APNS數據存儲在sqlite中。推送通知的後臺處理
當iPhone應用程序完全關閉時,即使不在後臺,也可以如何處理APNS處理。 例如應用程序完全關閉時,將APNS數據存儲在sqlite中。推送通知的後臺處理
中的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
}
http://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the- background-if-it-was-force-quit-by-the-user試試這個...... – vijeesh