小编Iss*_*sei的帖子

iPhone Objective-c检测屏幕锁定

我是使用Objective-c制作iPhone App的新手

我想制作在iPhone屏幕锁定时发送通知的应用程序(按下锁定按钮)如何制作此应用程序?

我正在尝试使用"applicationWillSuspend",但是

/*----------------------------------------*/
- (void)applicationWillSuspend
{
     NSLog(@"WillSuspend");
}
/*----------------------------------------*/
Run Code Online (Sandbox Code Playgroud)

此代码不起作用

我不确定何时调用applicationWillSuspend

拜托,给我一些知识

#import "AppDelegate.h"
#import <notify.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    // iOS8 Notification permit
    if ([UIApplication
         instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
        [[UIApplication sharedApplication]
         registerUserNotificationSettings:[UIUserNotificationSettings
                                           settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeSound
                                           categories:nil]];
    }
    return YES;

    int notify_token;
    notify_register_dispatch("com.apple.springboard.lockstate",
                             &notify_token,
                             dispatch_get_main_queue(),
                             ^(int token)
                             {
                                 uint64_t state = UINT64_MAX;
                                 notify_get_state(token, &state);
                                 if(state == 0) {
                                     NSLog(@"unlock device");
                                 } else {
                                     NSLog(@"lock device");
                                 } …
Run Code Online (Sandbox Code Playgroud)

iphone darwin objective-c ios appdelegate

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

标签 统计

appdelegate ×1

darwin ×1

ios ×1

iphone ×1

objective-c ×1