小编Roh*_*yap的帖子

有没有办法检查iOS设备是否被锁定/解锁?

我在我的应用程序中使用了GPS位置更新.我想检测iOS设备是否处于睡眠模式,这样我就可以关闭GPS位置更新并优化电池使用.我已经在iOS 6中尝试了pausesLocationupdates,但它无法正常工作.我想在设备进入睡眠模式后立即关闭GPS位置更新.我想检测设备中的锁定/解锁事件.

有没有办法实现这个功能?

到目前为止,我收到了下面给出的达尔文通知

-(void)registerForall
{
    //Screen lock notifications
    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                    NULL, // observer
                                    displayStatusChanged, // callback
                                    CFSTR("com.apple.iokit.hid.displayStatus"), // event name
                                    NULL, // object
                                    CFNotificationSuspensionBehaviorDeliverImmediately);


    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                    NULL, // observer
                                    displayStatusChanged, // callback
                                    CFSTR("com.apple.springboard.lockstate"), // event name
                                    NULL, // object
                                    CFNotificationSuspensionBehaviorDeliverImmediately);

    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                    NULL, // observer
                                    displayStatusChanged, // callback
                                    CFSTR("com.apple.springboard.hasBlankedScreen"), // event name
                                    NULL, // object
                                    CFNotificationSuspensionBehaviorDeliverImmediately);

    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                    NULL, // observer
                                    displayStatusChanged, // callback
                                    CFSTR("com.apple.springboard.lockcomplete"), // event name
                                    NULL, // object
                                    CFNotificationSuspensionBehaviorDeliverImmediately);

}
//call back
static void displayStatusChanged(CFNotificationCenterRef center, …
Run Code Online (Sandbox Code Playgroud)

gps sleep core-location ios

13
推荐指数
3
解决办法
2万
查看次数

当iOS设备进入睡眠模式时(当屏幕变黑时),有没有可以检测到该事件?

我想检测两个事件:

  1. 设备被锁定/解锁.
  2. 设备进入睡眠状态,屏幕变黑.

我能够在这里实现的第一个: 有没有办法检查iOS设备是否被锁定/解锁?

现在我想检测第二个事件,有什么方法可以做到吗?

iphone-privateapi ios sleep-mode

13
推荐指数
1
解决办法
1万
查看次数

pausesLocationUpdates在iOS 6中自动无法按预期工作

我想实现一个功能,我使用GPS进行更新,当用户不移动时,我希望暂停GPS更新.根据" 与位置服务保持同步 "视频,我这样做了:

 //Configure Location Manager
 self.theLocationManager = [[CLLocationManager alloc]init];
[self.theLocationManager setDelegate:self];
[self.theLocationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[self.theLocationManager setActivityType:CLActivityTypeFitness];

 NSLog(@"Activity Type Set: CLActivityTypeFitness");

[self.theLocationManager setPausesLocationUpdatesAutomatically:YES];
[self.theLocationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)

代表:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateLocations:(NSArray *)locations
{
    NSLog(@"Started location Updates");
}


- (void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager
{
    NSLog(@"Pausing location Updates");
}

- (void)locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager
{
    NSLog(@"Resuming location Updates");

    UIAlertView *pop = [[UIAlertView alloc]initWithTitle:@"Info" message:@"Location    Updates resumed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [pop show];
    [pop release];
}
Run Code Online (Sandbox Code Playgroud)

我没有得到所需的行为,当设备空闲时,代理人"didPause .."和"didResume ..."甚至没有被调用.

理想情况下,GPS更新必须停止和恢复,具体取决于设备的状态和CLActivityType,但不是这里的情况.

任何人都可以帮助我,我做错了什么?

提前致谢.

cllocationmanager ios6

5
推荐指数
1
解决办法
2698
查看次数