• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iOS 8 通知操作按钮未显示

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:05:31 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试使用操作按钮发送本地通知。 通知没问题。但是不显示操作按钮。 我正在使用 Xcode 6.3.2 iPhone 6 iOS 8.2


发送通知

UIApplication *myapp = [UIApplication sharedApplication];
UILocalNotification *test = [[UILocalNotification alloc] init];

if(test) {
    NSLog(@"Sending notification");

    test.alertBody = @"jothi test alert";
    test.alertTitle = @"kottapa";

    test.soundName = UILocalNotificationDefaultSoundName;
    test.alertAction = NSLocalizedString(@"View Details", nil);
    test.category = @"MY_CATEGORY";

    [myapp presentLocalNotificationNow:test];
}

在应用委托(delegate)中didFinishLaunchingWithOptions:

UIMutableUserNotificationAction *myAction =
[[UIMutableUserNotificationAction alloc] init];

myAction.identifier = @"MY_IDENTIFIER";        
myAction.title = @"Test Action";
myAction.activationMode = UIUserNotificationActivationModeBackground;
myAction.destructive = NO;
myAction.authenticationRequired = NO;

//------------

// First create the category
UIMutableUserNotificationCategory *inviteCategory =
   [[UIMutableUserNotificationCategory alloc] init];

// Identifier to include in your push payload and local notification
inviteCategory.identifier = @"MY_CATEGORY";

// Add the actions to the category and set the action context
[inviteCategory setActions[myAction]
                forContext:UIUserNotificationActionContextDefault];

// Set the actions to present in a minimal context
[inviteCategory setActions[myAction]
                forContext:UIUserNotificationActionContextMinimal];

NSSet *categories = [NSSet setWithObject:inviteCategory];

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

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

enter image description here



Best Answer-推荐答案


您的代码有效,您只需向左滑动通知即可看到操作按钮(或将其拉下,如果它从顶部以横幅形式呈现,则设备未锁定)。

另外,我猜你已经这样做了,只是没有包含代码,为了处理用户选择的操作,你需要在你的应用委托(delegate)中实现这个方法:

- (void)applicationUIApplication *)application handleActionWithIdentifierNSString *)identifier forLocalNotificationUILocalNotification *)notification completionHandlervoid(^)())completionHandler

enter image description here

关于iOS 8 通知操作按钮未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32109729/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap