gpt4 book ai didi

ios - 按钮不显示在 iOS 中的本地交互式通知中

转载 作者:行者123 更新时间:2023-11-29 12:14:25 25 4
gpt4 key购买 nike

我整个早上都在用这个把头撞在 table 上。我知道之前有人问过这个问题,但我真的不明白我的代码有什么问题。

这是我用来注册和发送交互式通知的代码。

提前致谢。

#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 的新手写得很好。此外,如果您正在调用它而只是简单地从问题中省略了它,那么您的问题可能在于您如何设置方法。现在它是一个类方法,我不确定它是否有意,但是,我的观点是,如果它不起作用,并且通知正在出现,只是不是类别操作,那么您可能应该正确调用它或将其更改为实例方法。

See the difference between the two here


你很亲近。您已正确设置所有内容,然后在最后摇摆不定。您应该这样调用您的 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"}];

}

并更改您的方法以正确反射(reflect)它是哪种方法。我在上面包含了一个链接来向您展示不同之处。您将像这样设置它:

-(void)sendLocalNotification:

+(void)sendLocalNotification:

关于ios - 按钮不显示在 iOS 中的本地交互式通知中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32362822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com