iOS开发本地通知
Posted Vijay的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS开发本地通知相关的知识,希望对你有一定的参考价值。
/* 本地通知:不通过网络,在本地实现的通知,自己发给自己 远程通知:必须通过网络,使用推送技术(APNs),实现通知 本地通知: 1.要完成可以接收的通知形式的注册 2.具体通知的设置 3.发送通知 */ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. //注意:ios8.0之后才需要进行专门的设置 [self settingLocalNotifacation]; return YES; } //设置我可以接收的通知形式 -(void)settingLocalNotifacation{ UIApplication *app = [UIApplication sharedApplication]; UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:0]; [app registerUserNotificationSettings:setting]; } @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(100, 100, 120, 30); [btn setTitle:@"发送本地通知" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; // Do any additional setup after loading the view, typically from a nib. } -(void)btnClicked:(UIButton *)btn{ //设置本地通知 UILocalNotification *localnoti = [[UILocalNotification alloc]init]; localnoti.alertTitle = @"放假"; localnoti.alertBody = @"明天放假"; localnoti.fireDate = [[NSDate date] dateByAddingTimeInterval:10]; //发送通知 UIApplication *app = [UIApplication sharedApplication]; [app scheduleLocalNotification:localnoti]; }
以上是关于iOS开发本地通知的主要内容,如果未能解决你的问题,请参考以下文章