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

    在苹果的Mac OSX 和IOS开发的API中有三个不同的"通知",包括:广播通知,本地通知和推送通知。

    本地通知只是应用所在设备上给用户通知,而推送通知是远程通知,他是由远程服务器推送过来的

    本节主要是讲的本地通知,虽然本地通知并没有任何的网络通信,但是他在编程方面与后面要介绍的推送通知非常相似。我们的例子中有三个按钮,“计划通知开始”按钮开启计划通知,他在10秒钟后到达。“停止所有计划通知”按钮式停止和取消已经开始的计划通知。“立刻发送通知”按钮式马上发出通知

    先看看计划通知开始的代码:

     1 - (IBAction)scheduleStart:(id)sender {
     2     
     3     UILocalNotification *localNotification=[[UILocalNotification alloc]init];
     4     
     5     //设置通知10秒后触发
     6     localNotification.fireDate=[[NSDate alloc]initWithTimeIntervalSinceNow:10];
     7     
     8     //设置通知消息
     9     localNotification.alertBody = @"计划通知,新年好";
    10     
    11     //设置通知标记数
    12     localNotification.applicationIconBadgeNumber=1;
    13     
    14     //设置通知出现时声音
    15     localNotification.soundName = UILocalNotificationDefaultSoundName;
    16     
    17     //设置动作按钮的标题
    18     localNotification.alertAction=@"View Details";
    19     
    20     //计划通知
    21     [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    22 }

    停止所有计划通知的按钮代码如下:

    1 - (IBAction)scheduleEnd:(id)sender {
    2     
    3     //结束计划通知
    4     [[UIApplication sharedApplication] cancelAllLocalNotifications];
    5 }

    立即发送通知按钮代码如下:

     1 - (IBAction)nowStart:(id)sender {
     2     
     3     UILocalNotification *localNotification = [[UILocalNotification alloc]init];
     4     
     5     //设置通知消息
     6     localNotification.alertBody = @"立即通知,新年好!";
     7     //设置通知徽章数
     8     localNotification.applicationIconBadgeNumber=1;
     9     
    10     //设置通知出现时候的声音
    11     localNotification.soundName=UILocalNotificationDefaultSoundName;
    12     
    13     //设置动作按钮的标题
    14     localNotification.alertAction = @"View Details";
    15     
    16     //立即发出通知
    17     [[UIApplication sharedApplication]presentLocalNotificationNow:localNotification];
    18 }
  • 相关阅读:
    perl -p -i -w -e
    s///|s()()i|/i|/g|U|u|L|l|Ul|split|join|匹配到hash|匹配到变量|`date`|$^I
    /^/m|/$/m||B|$&|$`|$'|变量捕获|()?|(?:pattern)|(?<LABEL>PATTERN)|$+{LABEL}|(|)|g{LABEL}
    ALG 4-3: Optimal Caching
    ALG 4-2: Scheduling to Minimize Lateness
    ALG 4-1: Interval Scheduling
    ALG 3-n: Practice
    ALG 3-6: Directed Acyclic Graphs and Topological Ordering (有向无环图与拓扑排序)
    ALG 3-5: Connectivity in Directed Graphs (有向图的连接性)
    ALG 3-4: Testing Bipartiteness
  • 原文地址:https://www.cnblogs.com/haibosoft/p/3694646.html
Copyright © 2011-2022 走看看