Pro*_*... -3 xcode objective-c plist ios
嗨StackOverflow开发人员,我有一个问题,我如何设置我的Info.plist可编程是或否.所以我的应用程序支持Backgroung Locaton更新.但是,正如所有iOS Devlopers都知道它像坚果一样杀死电池.所以我想检测iphone是否插入然后只支持后台访问,如果没有插入我们可以用户[locationmanger startMonitoringSignificantLocationChanges] ;. 谢谢你的帮助.
OP询问如何停止更新位置,答案是
CLLocationManager有一个stopUpdatingLocation:方法.
根据我的理解,属性列表用于声明您在后台使用位置服务的意图,并且在运行时的可访问性方面是只读的.因此,这似乎是正确的做法是要控制CLLocationManager通过它的方法,如stopUpdatingLocation:和 startMonitoringSignificantLocationChanges:.
您可以CLLocationManager使用电池通知注册电池通知,根据电池状态进行电池监控
[ [ UIDevice currentDevice ] setBatteryMonitoringEnabled:YES ];
[ [ NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(
reactToBatteryStatus) name:UIDeviceBatteryLevelDidChangeNotification object:nil ];
Run Code Online (Sandbox Code Playgroud)
通过此,您可以确定手机是否已插入.但是,根据Apple指南,您只应在需要时注册电池通知.所以要取消注册你使用
[ [ UIDevice currentDevice ] setBatteryMonitoringEnabled:NO ];
[ [ NSNotificationCenter defaultCenter ] removeObserver:self name:
UIDeviceBatteryLevelDidChangeNotification object:nil ];
Run Code Online (Sandbox Code Playgroud)
然后根据电池状态,您可以做您需要的.
+ (void) reactToBatteryStatus {
UIDeviceBatteryState batteryState = [ UIDevice currentDevice ].batteryState;
if ( batteryState == UIDeviceBatteryStateCharging || batteryState == UIDeviceBatteryStateFull )
{
// Device is plugged in.
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
361 次 |
| 最近记录: |