Ios 本地通知重复间隔
我的应用程序是关于显示学生时间表的,我想添加一个本地通知Ios 本地通知重复间隔,ios,notifications,uilocalnotification,Ios,Notifications,Uilocalnotification,我的应用程序是关于显示学生时间表的,我想添加一个本地通知repeatInterval 我打算用开关按钮来做这个 我尝试了此代码,但它现在不起作用: -(IBAction)theSwitch:(id)sender{ if (switcher.on) { NSCalendar *gregCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents
repeatInterval
我打算用开关按钮来做这个 我尝试了此代码,但它现在不起作用:
-(IBAction)theSwitch:(id)sender{
if (switcher.on) {
NSCalendar *gregCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponent = [gregCalendar components:NSYearCalendarUnit | NSWeekCalendarUnit fromDate:[NSDate date]];
[dateComponent setWeekday:3]; // For tuesday
[dateComponent setHour:13];
[dateComponent setMinute:41];
NSDate *fireDate = [gregCalendar dateFromComponents:dateComponent];
UILocalNotification *notification = [[UILocalNotification alloc]init];
[notification setAlertBody:@"ALARM!"];
[notification setFireDate:fireDate];
notification.repeatInterval = NSWeekCalendarUnit;
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
else {UIApplication *app=[UIApplication sharedApplication];
[app scheduleLocalNotification:nil];
}
}
因此,我需要更多的指导和一些如何实现这一目标的建议 如果您无法获得本地通知,请检查下面的代码 在AppDelegate.m文件中添加代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Handle launching from a notification
UILocalNotification *localNotification =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
NSLog(@"Recieved Notification %@", localNotification);
}
return YES;
}
添加方法以处理本地通知
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notification {
// Handle the notificaton when the app is running
NSLog(@"Recieved Notification %@", notification);
}
你面临的问题是什么?通知不来或回复问题?问题是当我打开应用程序时出现故障我的问题是当我打开应用程序时,我的应用程序出现故障并说
返回UIApplicationMain(argc,argv,nil,NSStringFromClass([AppDelegate class])代码>。我该怎么办?看起来当你试图添加本地通知应用程序时会崩溃,你能发布你的AppDelegate.m
文件的didfishLaunching
method code.AppDelegate.m`//处理从通知启动UILocalNotification*localNotification=[launchOptions objectForKey:uiapplicationaunchoptionslocalnotificationkey];if(localNotification){NSLog(@“received Notification%@”,localNotification);}返回YES;}`注意:我在view controller中添加了我的第一个代码。你能帮我吗???@Faisal:我需要查看你的AppDelegate.m
和ViewController.m
文件或相关代码。你可以共享你的代码吗?