sea*_*iao 2 objective-c ios uilocalnotification
我现在在应用程序中使用本地通知,但我发现一些奇怪的东西.
我设置并安排了这样的通知.
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) {
return;
}
NSDate *now = [[NSDate alloc] init];
now = [now dateByAddingTimeInterval:dayToFinish * 24 * 60 * 60];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit fromDate:now];
components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:now];
int month = [components month];
int day = [components day];
int year = [components year];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setYear:year];
[dateComps setMonth:month];
[dateComps setDay:day];
[dateComps setHour:18];
[dateComps setMinute:15];
[dateComps setSecond:0];
//There are a lot to set up the fire date, you could ignore it.
NSDate *fireDate = [calendar dateFromComponents:dateComps];
localNotif.fireDate = fireDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = [NSString stringWithFormat:@"Test message %@", self.name];
localNotif.applicationIconBadgeNumber = 1;
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:self.name forKey:@"ListRecordName"];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
Run Code Online (Sandbox Code Playgroud)
可以多次调用这部分代码来安排几个本地通知,现在奇怪的事情就来了.
我该如何解决这个问题,谢谢.
归档时间: |
|
查看次数: |
333 次 |
最近记录: |