gpt4 book ai didi

iphone - 如何为 UILocalnotification 增加/减少 application.badge 号码

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:08:30 26 4
gpt4 key购买 nike

当触发多个通知时我有 UILocalnotification 我希望应用程序角标(Badge)编号增加,当看到通知时我希望应用程序角标(Badge)编号减少,具体取决于取消通知/观看通知的数量

 - (UILocalNotification *)scheduleNotification :(int)remedyID
{
NSString *descriptionBody;
NSInteger frequency;

UILocalNotification *notif = [[UILocalNotification alloc] init];


descriptionBody =[[self remedyDetailsForRemedyID:remedyID] objectForKey:@"RemedyTxtDic"];
frequency = [[[self remedyDetailsForRemedyID:remedyID] objectForKey:@"RemedyFrequency"]intValue];

NSArray *notificationFireDates = [self fireDatesForFrequency:frequency];

for (NSDate *fireDate in notificationFireDates)
{
notif.timeZone = [NSTimeZone defaultTimeZone];


notif.repeatInterval = NSDayCalendarUnit;
notif.alertBody = [NSString stringWithString:descriptionBody];
notif.alertAction = @"Show me";
notif.soundName = UILocalNotificationDefaultSoundName;

notif.applicationIconBadgeNumber = 1;

notif.fireDate = fireDate;


NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:notif.alertBody, @"kRemindMeNotificationDataKey", [NSNumber numberWithInt:remedyID],kRemindMeNotificationRemedyIDKey,
nil];

notif.userInfo = userDict;

[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}

return notif;

}

}

- (void)cancelNotification:(int)remedyId
{


NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
NSLog(@"Cancelling... Before %d",[[[UIApplication sharedApplication]scheduledLocalNotifications]count]);

for (UILocalNotification *notification in notifications)
{

int notifRemedyId = [[notification.userInfo objectForKey:@"kRemindMeNotificationRemedyIDKey"]intValue];

NSLog(@"remedyID : %d",remedyId);
NSLog(@"notifyId : %d",notifRemedyId);
if (remedyId == notifRemedyId)
{
[[UIApplication sharedApplication] cancelLocalNotification:notification];
}

}

NSLog(@"Cancelling... After %d",[[[UIApplication sharedApplication]scheduledLocalNotifications]count]);

}

最佳答案

你可以简单地使用这两种方法,

-(void) incrementOneBadge{
NSInteger numberOfBadges = [UIApplication sharedApplication].applicationIconBadgeNumber;
numberOfBadges +=1;

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:numberOfBadges];
}

-(void) decrementOneBdge{
NSInteger numberOfBadges = [UIApplication sharedApplication].applicationIconBadgeNumber;
numberOfBadges -=1;

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:numberOfBadges];
}

关于iphone - 如何为 UILocalnotification 增加/减少 application.badge 号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16465947/

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