Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 根据日期打开和关闭堆芯位置_Objective C_Ios_Core Location - Fatal编程技术网

Objective c 根据日期打开和关闭堆芯位置

Objective c 根据日期打开和关闭堆芯位置,objective-c,ios,core-location,Objective C,Ios,Core Location,嗨,我正在开发一个应用程序,在后台使用核心位置,并通过位置通知推送通知用户 我使用以下代码注册重要的位置更改 CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease]; [locationManager startMonitoringSignificantLocationChanges]; 以及在更新到位置时运行后台任务 - (void)locationManager:(CLLo

嗨,我正在开发一个应用程序,在后台使用核心位置,并通过位置通知推送通知用户

我使用以下代码注册重要的位置更改

 CLLocationManager *locationManager = [[[CLLocationManager alloc] init]
 autorelease];
 [locationManager startMonitoringSignificantLocationChanges];
以及在更新到位置时运行后台任务

- (void)locationManager:(CLLocationManager *)manager
  didUpdateToLocation:(CLLocation *)newLocation
  fromLocation:(CLLocation *)oldLocation; 
但这项功能只在一周中的某一天需要。是否可以为CLLocationManager设置计时器,使其仅在一周中的特定日期处于活动状态

例如,仅为星期一启用“重要位置更改”,其余时间保持“重要位置更改”处于禁用状态


编辑:为了澄清,希望关闭定位服务(与呼叫[locationManager stopMonitoringSignificantLocationChanges]相同),即gps符号仅在周一激活,其他日子gps符号关闭。

谢谢!但我希望在不受影响的日子里关闭locationManager。这可能吗?你可以在else语句中这样做。当你的应用程序启动时,请测试哪一天启动,然后打开或关闭locationManager。如果用户选择不启动应用程序,则无法解决此问题?很像提醒应用程序,当你设置一个特定的日期+一个位置时,gps在达到指定的日期之前不会被激活。如果用户不启动该应用程序,你就无能为力了。基于位置的应用程序可能会有例外(应用程序在后台但未关闭),但我没有这方面的经验。很抱歉
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *today = [NSDate date];
NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:toDay];
NSInteger weekday = [weekdayComponents weekday];
if (weekday == 2) {
    // It is monday
} else {
    // It is another day of the week
}