gpt4 book ai didi

iphone - 无法在应用内取消 NSLocalNotification 和调用 NSLocalNotification

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

我有如下代码,但是通知出来后,我无法取消图标角标(Badge)。我应该添加什么代码才能启动应用程序、取消通知和重置图标角标(Badge)?

另一个问题是为什么通知只出现在手机的主屏幕上?在应用程序中,通知不会显示。谢谢。

display.text=[NSString stringWithFormat:@"%@A",display.text];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Utilities" message:@"Alarm added" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
// optional - add more buttons:

[alert show];

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object

NSDate *date = [NSDate date];

// Add one minute to the current time
NSDate *dateToFire = [date dateByAddingTimeInterval:20];

// Set the fire date/time
[localNotification setFireDate:dateToFire];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];


[localNotification setAlertAction:@"Done"];
[localNotification setAlertBody:@"(A)"];
[localNotification setHasAction: YES];
[localNotification setSoundName:UILocalNotificationDefaultSoundName];

[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

最佳答案

要删除角标(Badge)编号,您可以使用它

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

&

使用此代码取消所有本地通知:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

用这行代码取消一个本地通知:

[[UIApplication sharedApplication] cancelLocalNotification:theNotification];

关于iphone - 无法在应用内取消 NSLocalNotification 和调用 NSLocalNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15345788/

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