【发布时间】:2015-04-27 07:02:28
【问题描述】:
当 iPhone 应用程序完全关闭,即甚至不在后台时,如何进行 APNS 处理。 例如当应用程序完全关闭时,将 APNS 数据存储在 sqlite 中。
【问题讨论】:
标签: ios objective-c sqlite swift push-notification
当 iPhone 应用程序完全关闭,即甚至不在后台时,如何进行 APNS 处理。 例如当应用程序完全关闭时,将 APNS 数据存储在 sqlite 中。
【问题讨论】:
标签: ios objective-c sqlite swift push-notification
在 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
}
【讨论】: