gpt4 book ai didi

ios - 尝试使用 UrbanAirship 创建推送通知时,如何指定登陆哪个屏幕?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:04:41 24 4
gpt4 key购买 nike

我正在使用 UrbanAirship 添加推送通知。我的 AppDelegate.m 中有这两种方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Create Airship options dictionary and add the required UIApplication launchOptions
NSMutableDictionary *takeOffOptions = [NSMutableDictionary dictionary];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];

// Call takeOff (which creates the UAirship singleton), passing in the launch options so the
// library can properly record when the app is launched from a push notification. This call is
// required.
//
// Populate AirshipConfig.plist with your app's info from https://go.urbanairship.com
[UAirship takeOff:takeOffOptions];

// Set the icon badge to zero on startup (optional)
[[UAPush shared] resetBadge];

// Register for remote notfications with the UA Library. This call is required.
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];

// Handle any incoming incoming push notifications.
// This will invoke `handleBackgroundNotification` on your UAPushNotificationDelegate.
[[UAPush shared] handleNotification:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]
applicationState:application.applicationState];

// Override point for customization after application launch.
return YES;
}

和这个方法:

// Implement the iOS device token registration callback
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
UALOG(@"APN device token: %@", deviceToken);

// Updates the device token and registers the token with UA. This won't occur until
// push is enabled if the outlined process is followed.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *alias = [defaults objectForKey:@"user_id"];
[[UAPush shared] setAlias:@"test-alias"];
[[UAPush shared] registerDeviceToken:deviceToken];
}

我从这里的 UrbanAirship 说明中得到它们:https://docs.urbanairship.com/display/DOCS/Getting+Started:+iOS:+Push

但是我很困惑如何指定我希望推送通知登陆的屏幕。这是在哪里完成的?而且,我的服务器连同推送一起发送了一些 JSON。我在哪里以及如何从该 JSON 中提取数据?

谢谢!

最佳答案

您正在将 JSON 传递给 handleNotification 方法。这是您编写的方法,还是 urbanairship 代码的一部分? (我不确定除了服务器代码之外他们是否还提供客户端代码)。如果它是您编写的方法,您可以在该方法中访问来自 JSON 的数据。如果没有,您可以编写自己的方法并将相同的数据传递给它。

只有当通知到达时应用程序未运行并且用户点击通知打开应用程序时,您才能通过这种方式访问​​通知 JSON。如果用户点击应用启动图标,该数据将会丢失。

您可以使用 JSON 中的自定义属性来指定着陆屏幕。您有责任解析该属性并确定要显示的 View 。

您还应该实现 application:didReceiveRemoteNotification:,以便在应用程序在前台运行时通知到达时处理通知数据。

关于ios - 尝试使用 UrbanAirship 创建推送通知时,如何指定登陆哪个屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15664385/

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