【发布时间】:2019-09-20 23:16:20
【问题描述】:
我想知道应该回调什么函数,或者当我的应用被挂起/终止时我收到通知时。当我的应用程序处于前台/后台时,我能够处理,但是当应用程序被杀死时,我不确定如何以及在哪里处理或解析我的通知有效负载?
【问题讨论】:
标签: ios swift firebase push-notification
我想知道应该回调什么函数,或者当我的应用被挂起/终止时我收到通知时。当我的应用程序处于前台/后台时,我能够处理,但是当应用程序被杀死时,我不确定如何以及在哪里处理或解析我的通知有效负载?
【问题讨论】:
标签: ios swift firebase push-notification
在从通知打开应用程序时,您将在 application:didFinishedLaunchingWithOptions 方法中获取通知数据。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (launchOptions != nil)
{
// opened from a push notification when the app is closed
NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo != nil)
{
NSLog(@"userInfo->%@", [userInfo objectForKey:@"aps"]);
}
}
else
{
// opened app without a push notification.
}
}
斯威夫特 5.1
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
if launchOptions != nil {
// opened from a push notification when the app is closed
let userInfo = launchOptions?[.remoteNotification] as? [AnyHashable : Any]
if userInfo != nil {
if let object = userInfo?["aps"] {
print("userInfo->\(object)")
}
}
} else {
// opened app without a push notification.
}
}
【讨论】: