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. linux使用指导-debian/archlinux/LFS

    debian系统参考配置手册:https://www.debian.org/doc/manuals/debian-reference/index.en.html ArchLinux系统参考配置手册:s ...

  2. OpenCV颜色空间——HLS颜色空间

    引自:http://blog.csdn.net/zhangping1987/article/details/73699335 HLS颜色模型 HLS颜色空间,三个分量分别是色相(H).亮度(L).饱和 ...

  3. prepareEditor

    @Override public Component prepareEditor(TableCellEditor editor, int row, int column) { final Compon ...

  4. JTree常用方法

    private JTree jtNetDevice;//数组件申明private JScrollPane jspTree;//滚动面板申明 1.初始化     DefaultMutableTreeNo ...

  5. 通过shell脚本来rerun一个oozie调度失败的job,从而可以跳过执行失败的节点

    标题很长:通过shell脚本来rerun一个oozie调度失败的job,从而可以跳过执行失败的节点 不过目前从oozie调度测试的例子来看,oozie本身的retry好像并没有参数可以控制跳过失败的节 ...

  6. SpringBoot2 JPA No Identifier specified for entity的解决办法

    No Identifier specified for entity的错误 此类注解都在 import javax.persistence.*;包下     @Id     @GeneratedVal ...

  7. ClassNotFoundException和NoClassDefFoundError的解决办法

    程序在其他手机都没有问题,但在刷到版本稍微较低的平板或手机上时就会直接闪退,并报出以下异常: java.lang.RuntimeException: Unable to instantiate act ...

  8. SAP DBDI 网银接口实现案例

    在财务共享中心SSC实施中,为了提高AP和对账的效率,不可避免的需要实现和网上银行的集成.笔者为各位分析该案例如下: 为什么要上网银? 2).和SAP的无缝集成 3).直接在SAP中和银联对接 4). ...

  9. moodle中的完形填空题的文本编写方法

    moodle中的完形填空题的文本编写方法 [完形填空题]考题把一段文字挖去一些空,让考生根据上下文正确地完成这些填空.完型填空题中的一段短文可以包括各种题目,如选择,填空,和数字题等. 题目的编辑是在 ...

  10. JDBC删除表实例

    在本教程将演示如何在JDBC应用程序中删除一个数据库表. 在执行以下示例之前,请确保您已经准备好以下操作: 具有数据库管理员权限,以在给定模式中删除数据库表. 要执行以下示例,需要用实际用户名和密码替 ...