首页 > 代码库 > iOS开发本地通知
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开发本地通知
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。