[英]Buttons don't show on local interactive notification in iOS
我每天早上一直在把頭撞在桌子上。 我知道有人問過它,但是我真的不明白我的代碼有什么問題。
這是我用來注冊和發送交互式通知的代碼。
提前致謝。
#define kNotificationActionNo @"ActionKeyNo"
#define kNotificationActionYes @"ActionKeyYes"
#define kNotificationCategoryVendingMachine @"VendingMachineNotification"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[self registerForNotification];
...
}
+ (void)sendLocalNotification:(NSString*)message info:(NSDictionary*)infoDict {
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = message;
localNotification.fireDate = [NSDate date];
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.category = kNotificationCategoryVendingMachine;
localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
- (void)registerForNotification {
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:NSLocalizedString(@"YES_LEGEND", nil)];
[action1 setIdentifier:kNotificationActionYes];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:NSLocalizedString(@"NO_LEGEND", nil)];
[action2 setIdentifier:kNotificationActionNo];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:kNotificationCategoryVendingMachine];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
首先,
我看不到您實際上在didFinishLaunchingWithOptions:
方法中的任何地方調用了sendLocalNotification
方法。 您應該調用它以查看它是否真的觸發了,因為從美學上講,您已經完成了設置基於類別的通知應執行的所有操作。 榮譽,並為StackOverflow的新手寫的很好。 另外,如果您正在調用它,而只是簡單地從問題中省略了它,那么您的問題可能出在如何設置方法上。 現在它是一個類的方法,如果其有意或無意,我不知道,但是,我的觀點是,如果它不工作, 並通知被顯示出來,只是沒有類別的行動,那么你或許應該正確地調用或將其更改為實例方法。
你好親近 您已經正確設置了所有內容,然后最后搖擺了。 您應該這樣調用sendLocalNotification
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self sendLocalNotification:@"Estas cerca de una máquina expendedora. ¿Quieres realizar una compra?" info:@{@"type":@"near_vending"}];
}
並更改您的方法以正確反映它是哪種方法。 我在上面添加了一個鏈接,向您展示了它們之間的區別。 您將這樣設置:
-(void)sendLocalNotification:
不
+(void)sendLocalNotification:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.