在ios开发中 如何代码设置锁屏的时间 以及获取设置的锁屏时间
3条回答 默认 最新
- 坐在坟头调戏鬼丶 2016-02-22 07:39关注
获取的时间 , 我是不知道!可以监听锁屏, 程序在前台,这种比较简单。直接使用Darwin层的通知就可以了:
#import
#define NotificationLock CFSTR("com.apple.springboard.lockcomplete")
#define NotificationChange CFSTR("com.apple.springboard.lockstate")
#define NotificationPwdUI CFSTR("com.apple.springboard.hasBlankedScreen")
static void screenLockStateChanged(CFNotificationCenterRef center,void* observer,CFStringRef name,const void* object,CFDictionaryRef userInfo)
{
NSString* lockstate = (__bridge NSString*)name; if ([lockstate isEqualToString:(__bridge NSString*)NotificationLock]) { NSLog(@"locked."); } else { NSLog(@"lock state changed."); }
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, screenLockStateChanged, NotificationLock, NULL, CFNotificationSuspensionBehaviorDeliverImmediately); CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, screenLockStateChanged, NotificationChange, NULL, CFNotificationSuspensionBehaviorDeliverImmediately); //setScreenStateCb(); return YES;
}
解决 无用评论 打赏 举报