我是使用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",
¬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");
} …Run Code Online (Sandbox Code Playgroud)