在iOS8本地通知中设置动态按钮标题

在iOS8本地通知中设置动态按钮标题,ios,objective-c,swift,apple-push-notifications,uilocalnotification,Ios,Objective C,Swift,Apple Push Notifications,Uilocalnotification,我已经按照这里和其他地方的示例设置了1或2个按钮本地通知,并且工作正常。如果你需要像Accept/Delete/etc这样的固定按钮,那么这些例子就很好了,但是我需要为应用程序中正在发生的事情设置按钮标题。这是一个游戏,需要一个通用引擎。我需要能够设置按钮标题,以符合当时的需要。我有两个类别,所以我可以做一个按钮或两个按钮通知。注册通知时,似乎需要设置操作和类别。UIMutableUserNotificationCategory上的标题显示为“只读”。我知道这是可以做到的。例如,“间谍监视”游戏

我已经按照这里和其他地方的示例设置了1或2个按钮本地通知,并且工作正常。如果你需要像Accept/Delete/etc这样的固定按钮,那么这些例子就很好了,但是我需要为应用程序中正在发生的事情设置按钮标题。这是一个游戏,需要一个通用引擎。我需要能够设置按钮标题,以符合当时的需要。我有两个类别,所以我可以做一个按钮或两个按钮通知。注册通知时,似乎需要设置操作和类别。UIMutableUserNotificationCategory上的标题显示为“只读”。我知道这是可以做到的。例如,“间谍监视”游戏90%的时间都可以在通知中玩

在安排通知时是否设置了标题?我已经传递了带有处理响应所需数据的字典

这是AppDelegate端

NSString * const NotificationCategoryIdent1  = @"1BUTTON";
NSString * const NotificationCategoryIdent2  = @"2BUTTON";
NSString * const NotificationActionOneIdent = @"ACTION_ONE";
NSString * const NotificationActionTwoIdent = @"ACTION_TWO";

- (void)registerForNotification {

UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"Button 1"];
[action1 setIdentifier:NotificationActionOneIdent];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];

UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:@"Button 2"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];

UIMutableUserNotificationCategory *actionCategory2;
actionCategory2 = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory2 setIdentifier:NotificationCategoryIdent2];
[actionCategory2 setActions:@[action1, action2]
                forContext:UIUserNotificationActionContextDefault];

UIMutableUserNotificationCategory *actionCategory1;
actionCategory1 = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory1 setIdentifier:NotificationCategoryIdent1];
[actionCategory1 setActions:@[action1]
                forContext:UIUserNotificationActionContextDefault];

NSSet *categories = [NSSet setWithObjects:actionCategory1, actionCategory2, nil];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
                                UIUserNotificationTypeSound|
                                UIUserNotificationTypeBadge);

UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
                                             categories:categories];

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
以下是如何在视图控制器中设置通知

UILocalNotification* localNotification2 = [[UILocalNotification alloc] init];
localNotification2.fireDate = [NSDate dateWithTimeIntervalSinceNow:30];
localNotification2.alertBody = @"Alert Body2";
localNotification2.timeZone = [NSTimeZone defaultTimeZone];
localNotification2.soundName = UILocalNotificationDefaultSoundName;
localNotification2.category = @"2BUTTON";
//localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification2];

你的措辞让我有点困惑。你能用一句话来解释你的问题吗?我希望能够在运行时更改定义动作的标题。。。。这是一句话的版本,例如:有一次我调用actionCategory2时,我可能希望action1的标题是“向右”,action2的标题是“向左”,而下一次可能是“给物品”和“保留物品”。我不想预先定义游戏中每个可能的一个或两个按钮动作。定义的动作是什么?这是用于本地通知的。调用通知时,提供一个类别(UIMutableUserNotificationCategory)。类别由UIMutableUserNotificationAction组成。UIMutableUserNotificationAction有一个用作按钮标签的“标题”。它们是我所说的明确的行动。我可以有100个类别,每个类别都有分配给它们的不同操作,但最好允许我的程序在运行时提供按钮标签。为什么要在AppDelegate中注册它?当您拥有名称并将其设置为您想要的任何值时,为什么不在运行时执行此操作?