【发布时间】:2016-06-06 04:59:07
【问题描述】:
我是使用 Objective-c 制作 iPhone 应用程序的新手
我想制作当 iPhone 屏幕被锁定时发送通知的应用程序(按下锁定按钮) 如何制作这个应用程序?
我正在尝试使用“applicationWillSuspend”,但是
/*----------------------------------------*/
- (void)applicationWillSuspend
{
NSLog(@"WillSuspend");
}
/*----------------------------------------*/
此代码不起作用
我不确定何时调用 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",
¬ify_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");
}
}
);
}
【问题讨论】:
-
使用它
- (void)applicationDidEnterBackground:(UIApplication *)application委托方法 -
可能这就是你要找的东西:http://stackoverflow.com/a/14213968/5575752
-
参考以下链接,我认为它会帮助你stackoverflow.com/questions/7888490/…
-
@Issei 请检查我的更新答案。
标签: ios objective-c iphone appdelegate darwin