1、增加一个本地推送
//设置20秒之后 

NSDate *date = [NSDate dateWithTimeIntervalSinceNow:];

    //chuagjian一个本地推送

    UILocalNotification *noti = [[[UILocalNotification alloc] init] autorelease];

    if (noti) {

        //设置推送时间

        noti.fireDate = date;

        //设置时区

        noti.timeZone = [NSTimeZone defaultTimeZone];

        //设置重复间隔

        noti.repeatInterval = NSWeekCalendarUnit;

        //推送声音

        noti.soundName = UILocalNotificationDefaultSoundName;

        //内容

        noti.alertBody = @"推送内容";

        //显示在icon上的红色圈中的数子

        noti.applicationIconBadgeNumber = ;

        //设置userinfo 方便在之后需要撤销的时候使用

        NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];

        noti.userInfo = infoDic;

        //添加推送到uiapplication        

        UIApplication *app = [UIApplication sharedApplication];

        [app scheduleLocalNotification:noti];  

    }

2、程序运行时接收到本地推送消息

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notification

{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"接收到本地提醒 in app"

message:notification.alertBody

   delegate:nil

  cancelButtonTitle:@"确定"

  otherButtonTitles:nil];

[alert show];

//这里,你就可以通过notification的useinfo,干一些你想做的事情了

application.applicationIconBadgeNumber -= ;

}

3、取消一个本地推送

UIApplication *app = [UIApplication sharedApplication];

    //获取本地推送数组

    NSArray *localArr = [app scheduledLocalNotifications];

    //声明本地通知对象

    UILocalNotification *localNoti;

    if (localArr) {

        for (UILocalNotification *noti in localArr) {

            NSDictionary *dict = noti.userInfo;

            if (dict) {

                NSString *inKey = [dict objectForKey:@"key"];

                if ([inKey isEqualToString:key]) {

                    if (localNoti){

                        [localNoti release];

                        localNoti = nil;

                    }

                    localNoti = [noti retain];

                    break;

                }

            }

        }

        //判断是否找到已经存在的相同key的推送

        if (!localNoti) {

            //不存在 初始化

            localNoti = [[UILocalNotification alloc] init];

        }

        if (localNoti && !state) {

            //不推送 取消推送

            [app cancelLocalNotification:localNoti];

            [localNoti release];

            return;

        }

}

本地推送UILocalNotification(转)的更多相关文章

  1. 本地推送UILocalNotification

    //本地推送---无需网络,由本地发起 UILocalNotification *localNotification = [[UILocalNotification alloc]init]; //设置 ...

  2. Swift - 推送之本地推送(UILocalNotification)添加Button的点击事件

    上一篇讲到的本地推送是普通的消息推送,本篇要讲一下带按钮动作的推送消息 import UIKit @UIApplicationMain class AppDelegate: UIResponder, ...

  3. Swift - 推送之本地推送(UILocalNotification)

    // 本地推送通知是通过实例化UILocalNotification实现的.要实现本地化推送可以在AppDelegate.swift中添加代码实现,本事例是一个当App进入后台时推送一条消息给用户. ...

  4. 本地推送UILocalNotification的一些简单方法

    1.添加本地推送,需要在app添加推送.可以根据通知的userInfo的不同的键值对来区分不同的通知 UILocalNotification *notification = [[UILocalNoti ...

  5. SWIFT推送之本地推送(UILocalNotification)之二带按钮的消息

    上一篇讲到的本地推送是普通的消息推送,本篇要讲一下带按钮动作的推送消息,先上个图瞅瞅: 继上一篇的内容进行小小的改动: 在didFinishLaunchingWithOptions方法内进行以下修改 ...

  6. SWIFT推送之本地推送(UILocalNotification)

    本地推送通知是通过实例化UILocalNotification实现的.要实现本地化推送可以在AppDelegate.swift中添加代码实现,本事例是一个当App进入后台时推送一条消息给用户. 1.首 ...

  7. [转载]iOS本地推送-备用

    第一步:创建本地推送// 创建一个本地推送UILocalNotification *notification = [[[UILocalNotification alloc] init] autorel ...

  8. cocos2d-x中本地推送消息

    作者:HU 转载请注明,原文链接:http://www.cnblogs.com/xioapingguo/p/4038277.html  IOS下很简单: 添加一条推送 void PushNotific ...

  9. [iOS 高级] iOS远程推送与本地推送大致流程

    本地推送: UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notification!=nil) { ...

随机推荐

  1. shell脚本传递带有空格的参数的解决方法

    如下例子所示: #!/bin/sh dt= rdms_presql='select * from dm_general_stat where dimcode = "day" and ...

  2. PTC FlexPLM rfa 常用功能api

    1.根据款号查询产品 public LCSProduct GetProductByName(String SKC) throws WTException { //声明查询 PreparedQueryS ...

  3. Android Studio xcode单步调试 WebRTC Android & iOS

    mac环境 如何在 Android Studio 里单步调试 WebRTC Android 的 native 代码. WebRTC 代码下载 depot tools 是 chromium 代码库管理工 ...

  4. 安装Nginx+Lua+OpenResty开发环境配置全过程实例

    安装Nginx+Lua+OpenResty开发环境配置全过程实例 OpenResty由Nginx核心加很多第三方模块组成,默认集成了Lua开发环境,使得Nginx可以作为一个Web Server使用. ...

  5. ZARM in Linux & MIUI

    zram是Linux内核的一个模块,之前被称为“compcache”.zram通过在RAM内的压缩快设备上分页,直到必须使用硬盘上的交换空间,以避免在磁盘上进行分页,从而提高性能.由于zram可以用内 ...

  6. C++复合类型(结构体)

    其实c++的结构体可以理解为类似于python的字典,我个人理解, 但有区别 先看结构 #include <iostream> 关键字 标记成为新类型的名称 struct inflatab ...

  7. 【Python】Python加lxml实现图片解析下载功能

    1.下载网页:OpenHtml.py import urllib.request from urllib.parse import quote class HtmlLoader(object): de ...

  8. CentOS 6.8 安装 RabbitMQ

    放上来做个备份. 1.下载RabbitMQ http://www.rabbitmq.com/download.html 选择 RHEL/CentOS 6.x 下载即可. 或者 http://www.r ...

  9. 使用3ds Max制作简单卧室

    一.介绍 学习目标:熟练使用“标准基本体”和“扩展基本体”内的按钮来创建对象. 软件环境:3ds Max2015 二.实验步骤 1,启动3ds Max,使用“长方体”工具在场景中创建一个长方体作为空间 ...

  10. MyBatis打印输出SQL语句

    Hibernate是可以配置 show_sql 显示 自动生成的SQL 语句,用 format_sql 可以格式化SQL 语句,但如果用 mybatis 怎么实现这个功能呢?如果你搜索看一下,基本都是 ...