#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
/**
* 接收到本地通知的时候就会调用
* 程序在前台: 会调用 程序在后台:点击横幅 就算接收通知 也会调用 -> 程序活着就会调用
* @param application 应用
* @param notification 通知
*/
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
//调试:
//1>控制台
NSLog(@"%@",notification);
//2>添加控件
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 300)];
label.backgroundColor = [UIColor redColor];
label.text = [NSString stringWithFormat:@"%@",notification];
[self.window.rootViewController.view addSubview:label];
//跳转对应的界面
}
/**
* 程序从死到生 程序启动:1> 点击图标启动 2> 接收通知(点击横幅)
*
* @param application <#application description#>
* @param launchOptions <#launchOptions description#>
*
* @return <#return value description#>
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//UIApplicationLaunchOptionsLocalNotificationKey 接收到本地通知才会来到这里
UILocalNotification *info = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if (info) {
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 300)];
label.backgroundColor = [UIColor orangeColor];
[self.window.rootViewController.view addSubview:label];
//取出携带信息
label.numberOfLines = 0;
//NSDictionary *dict = info[@"UIConcreteLocalNotification"];
// NSArray *keys = [info allKeys];
//for (NSString *str in keys) {
// label.text = [NSString stringWithFormat:@"%@",str];
//}
//NSDictionary *dict1 = dict[@"user info"];
label.text = [NSString stringWithFormat:@"%@",info.userInfo];
//跳转对应的界面
}
return YES;
}