Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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
Objective c 如何实现iOS8交互通知_Objective C_Iphone_Push Notification_Ios8 - Fatal编程技术网

Objective c 如何实现iOS8交互通知

Objective c 如何实现iOS8交互通知,objective-c,iphone,push-notification,ios8,Objective C,Iphone,Push Notification,Ios8,我正在开发一个支持交互式通知的iOS8应用程序。但我不清楚交互式通知支持的功能以及如何发送/处理交互式通知。如果有人能举个例子,那将对我非常有帮助 提前感谢:) 首先,您需要创建通知操作 其次,您需要创建通知类别并设置其操作。UIUserNotificationActionContextDefault或UIUserNotificationActionContextMinimum 第三,您需要创建通知设置并分配上述类别 第四步是创建本地通知并为其分配类别的标识符 我想扩展一下苏拉夫·古普塔的回答

我正在开发一个支持交互式通知的iOS8应用程序。但我不清楚交互式通知支持的功能以及如何发送/处理交互式通知。如果有人能举个例子,那将对我非常有帮助

提前感谢:)

  • 首先,您需要创建通知操作
  • 其次,您需要创建通知类别并设置其操作。UIUserNotificationActionContextDefault或UIUserNotificationActionContextMinimum
  • 第三,您需要创建通知设置并分配上述类别
  • 第四步是创建本地通知并为其分配类别的标识符


  • 我想扩展一下苏拉夫·古普塔的回答。一旦您完成了Sourav解释的内容,您就必须实现代理以接收推送通知操作。代表们:

    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler {
    
    // Handle actions of local notifications here. You can identify the action by using "identifier" and perform appropriate operations
    
         if(completionHandler != nil)    //Finally call completion handler if its not nil
             completionHandler();
    }
    
    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler {
    
    // Handle actions of remote notifications here. You can identify the action by using "identifier" and perform appropriate operations
    
         if(completionHandler != nil)    //Finally call completion handler if its not nil
             completionHandler();
    }
    

    您可以在此处参考远程通知有效负载示例

    非常感谢@Sourav Gupta。但是远程通知呢?同样的代码也适用于远程通知。您只需要在推送负载中添加“category”键。“category”键应该具有与您在代码中定义的相同的标识符值。对不起,苏拉夫,我不理解这个概念。请你详细说明一下你的答案好吗?当我发送远程通知时,有效负载应该包含所有详细信息?您可以在代码中有n个不同类别,它们具有与之关联的不同操作。例如,在上面的代码中,我们有“notificationCategory”,它们具有操作“notificationAction1”、“notificationAction2”、“notificationAction3”。假设代码中有两个不同的类别。那么你将如何区分这两者呢。您只需要像这样添加分类键。根据要发送的类别标识符,它将显示相应的操作。{“警报”:“你好”,“类别”:“电子邮件”}它应该与前面的类似。唯一的更改是发送类别键,如“category”:“Email”在现有负载中,具体取决于您想要的类别
    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler {
    
    // Handle actions of local notifications here. You can identify the action by using "identifier" and perform appropriate operations
    
         if(completionHandler != nil)    //Finally call completion handler if its not nil
             completionHandler();
    }
    
    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler {
    
    // Handle actions of remote notifications here. You can identify the action by using "identifier" and perform appropriate operations
    
         if(completionHandler != nil)    //Finally call completion handler if its not nil
             completionHandler();
    }