Ios 每天只发送一个本地通知
就我而言,我希望通知每天只出现一次 这是我的代码:Ios 每天只发送一个本地通知,ios,uilocalnotification,ibeacon,Ios,Uilocalnotification,Ibeacon,就我而言,我希望通知每天只出现一次 这是我的代码: - (void)viewDidLoad { [super viewDidLoad]; /* * BeaconManager setup. */ self.beaconManager = [[ESTBeaconManager alloc] init]; self.beaconManager.delegate = self; NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"xxxalo
- (void)viewDidLoad
{
[super viewDidLoad];
/*
* BeaconManager setup.
*/
self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"xxxalotofnumbersxxx"];
self.beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID: uuid
major: 41270
minor: 64913
identifier: @"RegionIdentifier"];
[self.beaconManager startMonitoringForRegion:self.beaconRegion];
}
- (void)beaconManager:(ESTBeaconManager *)manager didEnterRegion:(ESTBeaconRegion *)region
{
UILocalNotification *notification = [UILocalNotification new];
notification.alertBody = @"Test";
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
我可以尝试通过在开始后立即插入来管理好它
if(notification.applicationIconBadgeNumber = 1;)
[self.beaconManager stopMonitoringForRegion:self.beaconRegion];
还有其他更好的解决办法吗?谢谢检查有多少本地通知已通过
[[UIApplication sharedApplication]scheduledLocalNotifications]调度返回UILocalNotifications数组的代码>。然后遍历所有UILocalNotification并检查它何时会显示其fireDate或userInfo
在UILocalNotification中使用repeatInterval属性跟踪每日通知,然后始终创建新通知
if (![self isScheduledToday:[UIApplication sharedApplication].scheduledLocalNotifications]) {
// add new notifcation as its not scheduled and set repeatMode to NSDayCalendarUnit;
}
/**
* returns if there a schedule for today
*/
- (BOOL)isScheduledToday:(NSArray *)notifications {
for (UILocalNotification *notification in notifications) {
if ([self isSameDay:notification.fireDate]) {
NSLog(@"Notifcation for today: %@", notification);
return YES;
}
}
return NO;
}
/**
* checks if date matches today by comparing year, month and day
*/
- (BOOL)isSameDay:(NSDate *)anotherDate {
NSCalendar *calendar = [NSCalendar currentCalendar];
calendar.timeZone = [NSTimeZone defaultTimeZone];
NSDateComponents *components1 = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[NSDate date]];
NSDateComponents *components2 = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:anotherDate];
return (components1.year == components2.year &&
components1.month == components2.month &&
components1.day == components2.day);
}
@mamo10看到我的基本实现更新,应该可以开始…我们可以在后台也这样做吗?我想在一天内为同一ibeacon显示3个通知,它也可以在后台工作。请帮忙