gpt4 book ai didi

iphone - iOS 5 使用 NSDictionary 从发送的推送通知中检索信息

转载 作者:行者123 更新时间:2023-12-03 19:31:07 24 4
gpt4 key购买 nike

是否可以使用 NSDictionary 从发送的推送通知中检索信息? (例如,获取警报负载包含的标题、消息和声音)。

我还想在负载中发送与标题或消息无关的信息(例如字符串)以供应用程序使用。再说一遍,这可能吗?

最佳答案

是的,两者皆有可能!

引用获取所需信息,执行以下操作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Push notification was received when the app was in the background

// .....
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(@"Launched from push notification: %@", dictionary);
// do something with your dictionary
}
}
// .....
return YES;
}

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
// Push notification received while the app is running

NSLog(@"Received notification: %@", userInfo);
// do something with your dictionary
}

关于iphone - iOS 5 使用 NSDictionary 从发送的推送通知中检索信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8911309/

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