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

标签 ios push-notification apple-push-notifications urbanairship.com

我正在使用 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/

相关文章:

apache-flex - Flex mobile 支持原生移动功能吗?

android - 使用 davibennun/laravel-push-notification 包的 Laravel 推送通知

ios - 分段控制激活

ios - 如何使用 UIBezierPath 为 Button 创建特定形状,如下面的带有 Swift 代码的附加图像所示?

android - React native firebase - android无法构建

ios - 推送通知在生产证书中不起作用

ios - 我的应用程序未出现在 iPhone 4 的通知中心中,但出现在 iPhone 4s 上

swift - Firebase iOS 从推送通知接收数据

ios - 使用 iOS Simulator 模拟 iPad 1

ios - 将 URL 分享到 App Store 中的应用程序