Nik*_*Loy 4 ios uilocalnotification ios8
我目前正在研究由8制作的交互式iOS通知,老实说,我真的很难看到我的按钮.使用下面的代码,我看不到我的按钮:
// INTERACIVE
UIMutableUserNotificationAction *acceptAction =
[[UIMutableUserNotificationAction alloc] init];
acceptAction.identifier = @"ACCEPT_IDENTIFIER";
acceptAction.title = @"Accept";
acceptAction.activationMode = UIUserNotificationActivationModeBackground;
acceptAction.destructive = NO;
acceptAction.authenticationRequired = NO;
UIMutableUserNotificationAction *maybeAction =
[[UIMutableUserNotificationAction alloc] init];
maybeAction.identifier = @"MAYBE_IDENTIFIER";
maybeAction.title = @"Maybe";
maybeAction.activationMode = UIUserNotificationActivationModeBackground;
maybeAction.destructive = NO;
maybeAction.authenticationRequired = YES;
UIMutableUserNotificationAction *declineAction =
[[UIMutableUserNotificationAction alloc] init];
declineAction.identifier = @"DECLINE_IDENTIFIER";
declineAction.title = @"Decline";
declineAction.activationMode = UIUserNotificationActivationModeBackground;
declineAction.destructive = YES;
declineAction.authenticationRequired = NO;
UIMutableUserNotificationCategory *inviteCategory =
[[UIMutableUserNotificationCategory alloc] init];
inviteCategory.identifier = @"INVITE_CATEGORY";
[inviteCategory setActions:@[acceptAction, maybeAction, declineAction]
forContext:UIUserNotificationActionContextDefault];
[inviteCategory setActions:@[acceptAction, declineAction]
forContext:UIUserNotificationActionContextMinimal];
NSSet *categories = [NSSet setWithObjects:inviteCategory, nil];
UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
localNotification.alertBody = @"Testing";
localNotification.category = @"INVITE_CATEGORY"; // Same as category identifier
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Run Code Online (Sandbox Code Playgroud)
对我的问题有什么想法吗?尽管互联网上有各种例子,但我显然是唯一一个遇到这个问题的人.
这里有一个非常好的教程:Code Ninja
代码中的所有内容都很好.我得请确保你不只是俯瞰到底发生了什么 - 如果你正在寻找在主屏幕上的通知,你向左滑动的通知显示的按钮?
这是我正在使用的(抱歉swift)
初始提示通知
var openAction = UIMutableUserNotificationAction()
openAction.identifier = "OPEN_IDENTIFIER"
openAction.title = "Open"
openAction.destructive = false
openAction.authenticationRequired = false
openAction.activationMode = .Foreground
var snoozeAction = UIMutableUserNotificationAction()
snoozeAction.identifier = "SNOOZE_IDENTIFIER"
snoozeAction.title = "Snooze"
snoozeAction.destructive = true
snoozeAction.authenticationRequired = false
snoozeAction.activationMode = .Background
var snoozeable = UIMutableUserNotificationCategory()
snoozeable.identifier = NOTE_SNOOZE_CAT
snoozeable.setActions([openAction, snoozeAction], forContext: .Default)
snoozeable.setActions([openAction, snoozeAction], forContext: .Default)
var notSnoozable = UIMutableUserNotificationCategory()
notSnoozable.identifier = NOTE_NO_SNOOZE_CAT
notSnoozable.setActions([openAction], forContext: .Default)
notSnoozable.setActions([openAction], forContext: .Default)
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Sound | .Alert |
.Badge, categories: NSSet(array:[snoozeable, notSnoozable])
))
Run Code Online (Sandbox Code Playgroud)
本地通知
var notification = UILocalNotification()
notification.fireDate = fireDate
notification.timeZone = NSTimeZone.defaultTimeZone()
notification.alertBody = "Alert Body"
notification.userInfo = userInfo
notification.category = blnCanSnooze ? NOTE_SNOOZE_CAT : NOTE_NO_SNOOZE_CAT
UIApplication.sharedApplication().scheduleLocalNotification(notification)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3606 次 |
| 最近记录: |