Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios-尝试使用UrbanAirship创建推送通知时,如何指定要在哪个屏幕上登录?_Ios_Push Notification_Apple Push Notifications_Urbanairship.com - Fatal编程技术网

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

ios-尝试使用UrbanAirship创建推送通知时,如何指定要在哪个屏幕上登录?,ios,push-notification,apple-push-notifications,urbanairship.com,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

我正在向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];
}
我从这里的城市航空说明中得到:

但我不知道如何指定希望推送通知到达的屏幕。在哪里做的?而且,我的服务器在推送的同时发送一些JSON。在哪里以及如何从JSON中提取数据


谢谢

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

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

您可以在JSON中使用自定义属性来指定登录屏幕。您将负责解析该属性并确定要显示的视图


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

您必须在应用程序代理中处理远程推送通知:

- (void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
您可以从此处访问根视图控制器,并触发其他视图控制器的显示

从文档中:

如果应用程序正在运行并收到远程通知,则应用程序将调用此方法来处理通知。此方法的实现应该使用通知来采取适当的行动。例如,您可以将其用作连接到服务器并下载等待应用程序的数据的信号

用户信息字典包含通过城市飞艇发送的附加数据


您可以在

中找到更多信息。简短的回答是:您没有(因为没有为您提供该功能。)

如果在应用程序运行时收到推送,则将调用
-[UIApplicationLegate应用程序:DidReceiveMemoteNotification:
。在实现此方法时,您负责采取适当的操作(例如显示消息、导航到应用程序的特定区域)


:

如果应用程序正在运行并收到远程通知,则应用程序 调用此方法以处理通知。你实施的 此方法应使用通知选择适当的课程 行动纲领。例如,您可以将其用作连接到服务器的信号 服务器并下载正在等待应用程序的数据

userInfo字典包含值为另一个的aps键 字典。虽然您不需要aps中的信息 字典,您可以使用以下键检索其内容:

userInfo字典还可以具有由定义的自定义数据 根据JSON模式提供程序。自定义数据的属性 应在与aps字典相同的级别指定。然而, 自定义属性不应用于海量数据传输 因为每个通知都有严格的大小限制(256字节)和 不保证交货


谢谢,我只是想澄清一下,如果我想将用户发送到一个特定的屏幕,我必须首先将他们发送到ViewController,然后从ViewController发送到该屏幕?(我的ViewController是我的根视图控制器)。城市飞艇SDK不知道ios应用程序的结构,它无法显示特定的屏幕。是的,您可以将调用转发到根视图控制器并在其中处理通知。在我们的应用程序中,我们有一个选项卡式视图控制器作为根视图控制器,并有从应用程序委托调用的特殊方法(例如“showMapTab”)。json是我编写的,用于将数据打包到推送中。这是我的朋友寄来的server@Genadinik没错。它包含从服务器发送的通知有效负载。