【发布时间】:2017-10-22 00:19:59
【问题描述】:
我现在有这个问题,我需要在应用程序在后台时处理推送通知的信息,我的意思是,即使不点击通知。 这意味着这个 application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 必须在后台调用! 这是我的代码
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(@"full message %@", userInfo);
NSDictionary *aps = [userInfo objectForKey:@"aps"];
NSLog(@"full aps %@", aps);
NSString *custom = [userInfo objectForKey:@"custom"];
NSLog(@"full custom %@",custom);
completionHandler(UIBackgroundFetchResultNewData);
[[NSNotificationCenter defaultCenter] postNotificationName:@"notificationRemote" object:nil userInfo:userInfo];
}
我真的需要处理这些信息,以便每次收到任何通知时都将其保存到本地,无论我点击推送通知。
我搜索并发现我的负载需要内容可用,但我在 Firebase 控制台通知中找不到它。
【问题讨论】:
-
嗨,我有一个类似的场景,但需要稍作修改,比如当我收到推送通知时,应用程序应该在后台激活并执行中给出的任务,(如用户的位置更新代码), - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo ,但在用户点击通知之前,我的应用程序不会激活。那么,当应用程序处于后台时,我将如何完成这项工作?有谁知道这个的解决方案吗?
-
@Moxarth 你找到解决方案了吗?
标签: ios objective-c firebase push-notification apple-push-notifications