Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.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 如何处理推送通知中的操作按钮_Ios_Iphone_Push Notification_Watchkit_Apple Watch - Fatal编程技术网

Ios 如何处理推送通知中的操作按钮

Ios 如何处理推送通知中的操作按钮,ios,iphone,push-notification,watchkit,apple-watch,Ios,Iphone,Push Notification,Watchkit,Apple Watch,处理Apple Watch通知:-因此,如果我在通知界面(从对象库)中添加按钮,则错误为: 通知界面不支持按钮 PushNotificationPayload.apns具有如下WatchKit模拟器动作: "WatchKit Simulator Actions": [ { "title": "View", "identifier": "firstButtonAction" } ], 模拟器向我展示了这一点 现在我的问题是,当从服务器发送Pus

处理Apple Watch通知:-因此,如果我在通知界面(从对象库)中添加按钮,则错误为:

通知界面不支持按钮

PushNotificationPayload.apns
具有如下
WatchKit模拟器动作

"WatchKit Simulator Actions": 
[
    {
        "title": "View",
        "identifier": "firstButtonAction"
    }
],
模拟器向我展示了这一点

现在我的问题是,当从服务器发送
PushNotification
时,如何处理这个
View
按钮

如果aps
aps
文件中包含的操作按钮是Apple Watch的唯一选项

如何使用指定的密钥从通知字典中的服务器发送它?

如何更改动作按钮背景颜色?

有谁能给我一个样本
aps
文件,其中包括设备
苹果手表
ActionButton
,而不是
模拟器的

我只是通过将
WatchKit模拟器操作
键更改为
WatchKit操作
键进行测试,但它不显示任何操作按钮

根据@vivekDas在回答中的建议,我在
aps
中替换为:

"alert" : {
     "body" : "Acme message received from Johnny Appleseed",
     "action-loc-key" : "VIEW",
     "action" : [
        {
           "id" : "buttonTapped",
           "title" : "View"
        }
     ]
  }
但Xcode中的模拟器确实显示了一个动作按钮

我认为这可能在设备上运行
苹果手表
,这是…?


您对此有何建议。

使用Json有效负载,如下所示

{
    "aps": {
         "badge": 10,
         "alert": "Your message",
         "sound": "cat.caf"
    }
}
检查这个苹果文档链接


通知有效负载部分。

我已经为此挣扎了两个小时,所以这就是我在生产中通过real APNS Serv为通知按钮所做的工作

1) 在appDelegate的父应用中注册类别:

- (void)registerSettingsAndCategories {
    // Create a mutable set to store the category definitions.
    NSMutableSet* categories = [NSMutableSet set];

    // Define the actions for a meeting invite notification.
    UIMutableUserNotificationAction* acceptAction = [[UIMutableUserNotificationAction alloc] init];
    acceptAction.title = NSLocalizedString(@"Repondre", @"Repondre commentaire");
    acceptAction.identifier = @"respond";
    acceptAction.activationMode = UIUserNotificationActivationModeForeground; //UIUserNotificationActivationModeBackground if no need in foreground.
    acceptAction.authenticationRequired = NO;

    // Create the category object and add it to the set.
    UIMutableUserNotificationCategory* inviteCategory = [[UIMutableUserNotificationCategory alloc] init];
    [inviteCategory setActions:@[acceptAction]
                    forContext:UIUserNotificationActionContextDefault];
    inviteCategory.identifier = @"respond";

    [categories addObject:inviteCategory];

    // Configure other actions and categories and add them to the set...

    UIUserNotificationSettings* settings = [UIUserNotificationSettings settingsForTypes:
                                            (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound)
                                                                             categories:categories];

    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
2) 从您的Apns服务器添加类别(对于我来说是“响应”)

3) 在WatchKitExtension中,传递了以下数据:

- (void)handleActionWithIdentifier:(NSString *)identifier  forRemoteNotification:(NSDictionary *)remoteNotification{

     if ([identifier isEqualToString:@"respond"]) {
//Do stuff Here to handle action... 
     }
}
4) 在父应用程序的appDelegate中:

- (void) application:(UIApplication *)application
handleActionWithIdentifier:(NSString *)identifier
     forRemoteNotification:(NSDictionary *)userInfo
         completionHandler:(void (^)())completionHandler {
    completionHandler();
}
警告!您还必须在父应用程序中处理此操作(因为当您向下平移通知时,响应按钮在iphone上也将可见。在:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

你不能在模拟器中检查推送通知。嘿,有同样的问题…你解决了吗?点击“查看按钮”,你会在UIApplication委托方法中得到一个回调“-(void)application:(UIApplication*)application DidReceiveMemoteNotification:(NSDictionary*)userInfo”在这里,你必须处理动作。他不是这样要求的……他想在apple watch(设备)上的推送通知中显示一个按钮。你给出的json示例没有动作按钮,这正是代码所做的。一旦你注册了类别(步骤1),步骤2中的json就会在我的示例中显示按钮“Repondre”这是在实际设备上显示按钮的方式(没有watchkit模拟器操作,这在实际设备上不起作用。)明白了,谢谢!你的解决方案可以工作…被Xcode中提供的“watchkit模拟器操作”json搞糊涂了。没问题。.“watchkit模拟器操作”“一开始我也很困惑……我在我的aps服务器上尝试了WatchKit操作,这就是方法。@JeremyLuisetti:在
handleActionWithIdentifier
方法中//在这里做些什么……我需要做些什么来呈现一个接口控制器?我尝试了[self-pushControllerWithName…]但这不是一个选项,重新加载RootControllerWithNames…只是打开watch应用程序,它不会转到我想要的特定页面
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {