Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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_Xcode_Unnotificationrequest - Fatal编程技术网

当应用程序在ios中被终止时,通知不显示并带有操作按钮

当应用程序在ios中被终止时,通知不显示并带有操作按钮,ios,xcode,unnotificationrequest,Ios,Xcode,Unnotificationrequest,我已经完成了以下代码来显示动作按钮,同时通知使用一个信号。但当应用程序被终止时,通知不会出现。它在后台/前台模式下工作正常。但当应用程序不在任务栏中时,甚至通知也会停止。没有动作按钮,它工作得很好 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOption

我已经完成了以下代码来显示动作按钮,同时通知使用一个信号。但当应用程序被终止时,通知不会出现。它在后台/前台模式下工作正常。但当应用程序不在任务栏中时,甚至通知也会停止。没有动作按钮,它工作得很好

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
 {
     if( !error ) {
         [[UIApplication sharedApplication] registerForRemoteNotifications];

         NSLog( @"Push registration success." );

     } else {
         NSLog( @"Push registration FAILED" );

}];

UNNotificationCategory *modifyCategory = [UNNotificationCategory categoryWithIdentifier:CYLInviteCategoryIdentifier actions:@[] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];

UNNotificationAction* snoozeAction = [UNNotificationAction
                                          actionWithIdentifier:@"ACCEPT_ACTION"
                                          title:@"Accept"
                                          options:UNNotificationActionOptionForeground];

UNNotificationAction* stopAction = [UNNotificationAction
                                        actionWithIdentifier:@"DECLINE_ACTION"
                                        title:@"Decline"
                                        options:UNNotificationActionOptionDestructive];

UNNotificationCategory* actionCategory = [UNNotificationCategory
                                               categoryWithIdentifier:@"INCOMING_CALL"
                                               actions:@[snoozeAction, stopAction]
                                               intentIdentifiers:@[]
                                               options:UNNotificationCategoryOptionNone];

[center setNotificationCategories:[NSSet setWithObjects: modifyCategory, actionCategory,
                                       nil]];

有两种方法可以在推送通知中实现此操作处理。 1) 简单地注册您当前正在使用的UNUserNotificationCenter,但您面临操作按钮未在终止模式下显示的问题

因此,请检查您的有效负载用户信息字典标识符和类别以及您共享的配置

以下是我的代码,请检查此Swift代码

private func setNotificationCategories() {

let likeAction = UNNotificationAction(identifier: "like", title: "Like", options: [])
let replyAction = UNNotificationAction(identifier: "reply", title: "Reply", options: [])
let archiveAction = UNNotificationAction(identifier: "archive", title: "Archive", options: [])
let  ccommentAction = UNTextInputNotificationAction(identifier: "comment", title: "Comment", options: [])


let localCat =  UNNotificationCategory(identifier: "category", actions: [likeAction], intentIdentifiers: [], options: [])

let customCat =  UNNotificationCategory(identifier: "recipe", actions: [likeAction,ccommentAction], intentIdentifiers: [], options: [])

let emailCat =  UNNotificationCategory(identifier: "email", actions: [replyAction, archiveAction], intentIdentifiers: [], options: [])

UNUserNotificationCenter.current().setNotificationCategories([localCat, 

customCat, emailCat])
}
我更新了你的代码请检查一下

UNNotificationCategory *modifyCategory = [UNNotificationCategory categoryWithIdentifier:CYLInviteCategoryIdentifier actions:@[] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];

UNNotificationAction* snoozeAction = [UNNotificationAction
                                          actionWithIdentifier:@"ACCEPT_ACTION"
                                          title:@"Accept"
                                          options:[]];

UNNotificationAction* stopAction = [UNNotificationAction
                                        actionWithIdentifier:@"DECLINE_ACTION"
                                        title:@"Decline"
                                        options:[]];

UNNotificationCategory* actionCategory = [UNNotificationCategory
                                               categoryWithIdentifier:@"INCOMING_CALL"
                                               actions:@[snoozeAction, stopAction]
                                               intentIdentifiers:@[]
                                               options:[]];



[center setNotificationCategories:[NSSet setWithObjects: modifyCategory, actionCategory,
                                       nil]];
改变只是不设置选项


2) 使用通知扩展可以设计有吸引力的推送通知。为此,我建议您更喜欢这个博客。有两种方法可以在推送通知中实现此操作处理。 1) 简单地注册您当前正在使用的UNUserNotificationCenter,但您面临操作按钮未在终止模式下显示的问题

因此,请检查您的有效负载用户信息字典标识符和类别以及您共享的配置

以下是我的代码,请检查此Swift代码

private func setNotificationCategories() {

let likeAction = UNNotificationAction(identifier: "like", title: "Like", options: [])
let replyAction = UNNotificationAction(identifier: "reply", title: "Reply", options: [])
let archiveAction = UNNotificationAction(identifier: "archive", title: "Archive", options: [])
let  ccommentAction = UNTextInputNotificationAction(identifier: "comment", title: "Comment", options: [])


let localCat =  UNNotificationCategory(identifier: "category", actions: [likeAction], intentIdentifiers: [], options: [])

let customCat =  UNNotificationCategory(identifier: "recipe", actions: [likeAction,ccommentAction], intentIdentifiers: [], options: [])

let emailCat =  UNNotificationCategory(identifier: "email", actions: [replyAction, archiveAction], intentIdentifiers: [], options: [])

UNUserNotificationCenter.current().setNotificationCategories([localCat, 

customCat, emailCat])
}
我更新了你的代码请检查一下

UNNotificationCategory *modifyCategory = [UNNotificationCategory categoryWithIdentifier:CYLInviteCategoryIdentifier actions:@[] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];

UNNotificationAction* snoozeAction = [UNNotificationAction
                                          actionWithIdentifier:@"ACCEPT_ACTION"
                                          title:@"Accept"
                                          options:[]];

UNNotificationAction* stopAction = [UNNotificationAction
                                        actionWithIdentifier:@"DECLINE_ACTION"
                                        title:@"Decline"
                                        options:[]];

UNNotificationCategory* actionCategory = [UNNotificationCategory
                                               categoryWithIdentifier:@"INCOMING_CALL"
                                               actions:@[snoozeAction, stopAction]
                                               intentIdentifiers:@[]
                                               options:[]];



[center setNotificationCategories:[NSSet setWithObjects: modifyCategory, actionCategory,
                                       nil]];
改变只是不设置选项


2) 使用通知扩展可以设计有吸引力的推送通知。为此,我建议您更喜欢这个博客

请查看我的答案,您需要在推送通知中添加“内容可用”:1payload@balkaransingh我已将内容设置为可用:1在我的有效负载中。但由于操作按钮的原因,仍然没有收到通知。是否可以在应用程序终止模式下显示操作按钮?设置NotificationCategories后的RegisterForRemotionTifications。然后,请检查我的答案,您需要在推送通知中添加“内容可用”:1payload@balkaransingh我已将内容设置为可用:1在我的有效负载中。但由于操作按钮的原因,仍然没有收到通知。是否可以在应用程序终止模式下显示操作按钮?设置NotificationCategories后的RegisterForRemotionTifications。然后试试看