gpt4 book ai didi

ios - 推送通知的后台处理

转载 作者:行者123 更新时间:2023-11-29 02:04:57 24 4
gpt4 key购买 nike

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

关于ios - 推送通知的后台处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29889209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com