本地通知

#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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 许多集成的步骤个推官网都有了,这里只写关于推送的远程推送和本地通知的步骤和代码。APP在后台时:走苹果的APNS通...
    AllureJM阅读 7,841评论 1 9
  • 作者雷潮关注 2016.02.01 00:18*字数 1921阅读 7038评论 1喜欢 35 这里是指推送通知跟...
    对面来个小胖子阅读 2,571评论 0 1
  • 一、本地推送/本地通知 是什么? (名称概念)本地推送,其实也就是本地通知,它们指的是同一种概念,只是叫法不同,下...
    Jacob_LJ阅读 10,116评论 3 4
  • 概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户感兴趣的那么通过通知...
    莫离_焱阅读 11,609评论 1 8
  • 我也不知道为什么就会爱上了你, 可能是你活泼可爱, 也可能是你聪慧大方。 赶巧了我也喜欢活泼可爱,聪慧大方, 所以...
    少女所见之荒原阅读 1,657评论 3 1

友情链接更多精彩内容