2 liu bin home liu_bin_home 于 2016.02.19 14:08 提问

iOS 开发 如何设置和获取锁屏的时间长短 1C

在ios开发中 如何代码设置锁屏的时间 以及获取设置的锁屏时间

2个回答

bu121238
bu121238   2016.02.22 15: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;

}

bu121238
bu121238   2016.02.22 15: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;

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!