zoukankan      html  css  js  c++  java
  • 本地通知 LocalNotification

    本地通知 LocalNotification 

    在Appdelegate中实现以下两个方法

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        //设置桌面红点内的数字
    //    application.applicationIconBadgeNumber = 0;
        
        //请求通知权限
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge) categories:nil];
        [application registerUserNotificationSettings:settings];
        
        return YES;
    }

    收到本地通知的代理方法

    1.点击本地通知弹框

    2.程序在前台, 收到本地通知

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
        NSLog(@"%@", notification);
    }

    添加一个button到ViewController中

    #import "ViewController.h"
    
    @interface ViewController ()
    - (IBAction)localNoti:(id)sender;
    @end
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad]; 
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (IBAction)localNoti:(id)sender {
        //创建本地通知
        UILocalNotification *notification = [[UILocalNotification alloc] init];
        //提示框内容
        notification.alertBody = @"起床啦";
        //提示框标题
        notification.alertTitle = @"醒啦";
        //通知声音
        notification.soundName = UILocalNotificationDefaultSoundName;
        //触发时间
        notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
        //icon旁边的数字
        notification.applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1;
        //本地通知重复
        notification.repeatInterval = NSCalendarUnitMinute;
        //发送通知
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    }
    @end

    cmd + shift + H 退出程序, 本地通知就弹出

     

     

  • 相关阅读:
    Check the string
    最简单的
    第七届ACM程序设计竞赛 (SDIBT)
    Cutie Pie
    CSS3 :nth-of-type() 与 nth-child()选择器
    Ajax 完整教程 转载地址:http://www.cnblogs.com/Garden-blog/archive/2011/03/11/1981778.html(转)
    排序:二元选择排序
    排序:堆排序
    排序:直接插入排序 稳定 n*n
    排序:冒泡和改进
  • 原文地址:https://www.cnblogs.com/OrangesChen/p/5071403.html
Copyright © 2011-2022 走看看