如何处理推送通知中的操作按钮 [英] How to Handle Action Buttons in Push Notifications

查看:176
本文介绍了如何处理推送通知中的操作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Apple Watch通知: - 因此,如果我在通知界面中添加按钮(来自对象Lib),则错误为:

Working on Apple Watch Notifications:- so if i add button in Notification Interface (from object Lib) then the error is :

通知界面中不支持按钮

PushNotificationPayload.apns 具有 WatchKit模拟器操作喜欢这个:

"WatchKit Simulator Actions": 
[
    {
        "title": "View",
        "identifier": "firstButtonAction"
    }
],

并且模拟器向我显示

现在我的问题是,我该如何处理从服务器发送 PushNotification 时查看按钮,

Now my Question is, How can I Handle this View Button when send a PushNotification from server,

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

If the aps file contain the action button is the only option for Apple Watch,

如何从服务器发送它ñ带指定键的otification词典?

如何更改操作按钮BG颜色?

有人请给我样本 aps 文件,其中包含 ActionButton for Device Apple Watch 不适用于模拟器

Will anyone please give me the sample aps file that include ActionButton for Device the Apple Watch not for the Simulator

我只需通过更改 WatchKit模拟器操作 KeyKit操作的键键但它没有显示操作按钮。

I just test by changing the WatchKit Simulator Actions Key to WatchKit Actions Key but it shows no Action Button.

正如@vivekDas在答案中所建议的那样,我通过将 aps 替换为:

As suggested by @vivekDas in Answer, I checked by replacing in the aps as :

"alert" : {
     "body" : "Acme message received from Johnny Appleseed",
     "action-loc-key" : "VIEW",
     "action" : [
        {
           "id" : "buttonTapped",
           "title" : "View"
        }
     ]
  }

但Xcode中的模拟器确实显示了一个动作按钮。

but simulator in Xcode does show an action button.

我认为这可能会在设备上运行 Apple Watch ,这是......?

I think this may run on Device Apple Watch, is this...?

您对此有什么建议。

推荐答案

我一直在努力工作两个小时,所以这就是我通过真正的APNS服务生产通知按钮的方式,

I've been struggling with this for two Hours, so this is how I do for notifications buttons in production, via real APNS Serv,

1)注册中的类别你的appDelegate的父应用程序:

1) Register for the category in your appDelegate's parent app :

- (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服务器添加类别(对我来说回复)

2) From your Apns server add the category (for me "respond")

{"aps":{"alert":"bla","category":"respond","badge":2}}

3)在WatchKitExtention中,您传入了数据:

3) In your WatchKitExtention, you have the data passed in :

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

     if ([identifier isEqualToString:@"respond"]) {
//Do stuff Here to handle action... 
     }
}

4)在您的父应用程序的appDelegate中:

4) In your Parent app's appDelegate :

- (void) application:(UIApplication *)application
handleActionWithIdentifier:(NSString *)identifier
     forRemoteNotification:(NSDictionary *)userInfo
         completionHandler:(void (^)())completionHandler {
    completionHandler();
}

警告!你必须在你的父应用程序中处理这个动作(因为当你平息通知时,响应按钮也会在iphone上可见。在:

Warning ! you'll have to handle this action too in your Parent app ( because the respond button will be visible too on iphone when you pan down the notification. in the :

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

这篇关于如何处理推送通知中的操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆