原帖请看:http://cocoathings.blogspot.com/2013/01/introduction-to-user-notifications-in.html

想要实现如图这样的notification popup

弹出notification的代码如下

NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = @"Hello, World!";
notification.informativeText = [NSString stringWithFormat:@"details details details"];
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];

但是这个popup并不是默认显示的,想要让他show出来还必须在程序里实现下面的方法:

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification
{
return YES;
}

然后把NSUserNotificationCenter.的delegate设置为自己的程序,一般在主程序AppDelegate.m中实现即可(上面那个函数也在这个文件里)

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
}

需要注意的是,想要成功设置delegate还必须让AppDelegate支持NSUserNotificationCenterDelegate 协议,即在它的头文件里加上这个协议即可。

然后运行程序就OK了。

【转载】User notification 的实现方法的更多相关文章

  1. 【转载】C#使用Trim方法去除字符串前后的所有空格

    在C#语言程序开发过程中,很多时候需要对字符串对象的前后空格进行去除,此时就需要使用到Trim()方法来实现这个功能,Trim()方法可以快速去除字符串前端和后端的所有空格. 例如有个字符:strin ...

  2. 【转载】C#通过IndexOf方法判断某个字符串是否包含在另一个字符串中

    C#开发过程中针对字符串String类型的操作是常见操作,有时候需要判断某个字符串是否包含在另一个字符串,此时可以使用IndexOf方法以及Contain方法来实现此功能,Contain方法返回Tru ...

  3. 【转载】C#使用FirstOrDefault方法快速查找List集合中符合条件的第一个实体

    在C#的List集合的操作中,有时候我们需要根据相关条件快速从List集合中获取到第一个符合条件的实体对象,例如有个全校班级的List集合,我们需要根据班级代码快速从List集合中查找出班级信息.可以 ...

  4. ListView:The content of the adapter has changed but ListView did not receive a notification终极解决方法

    使用ListView时遇到如下的异常信息: 10-26 18:30:45.085: E/AndroidRuntime(7323): java.lang.IllegalStateException: T ...

  5. Android The content of the adapter has changed but ListView did not receive a notification终极解决方法

    这几天做一个自动扫描SD卡上所有APK文件的小工具,扫描过程中会把APK添加到LISTVIEW中显示,结果出现以下错误:(有时候触摸更新数据时候,触摸listview也会报错) E/AndroidRu ...

  6. 转载:Java多线程中join方法的理解

    转载自:http://uule.iteye.com/blog/1101994 thread.Join把指定的线程加入到当前线程,可以将两个交替执行的线程合并为顺序执行的线程.比如在线程B中调用了线程A ...

  7. 转载:[Java]读取文件方法大全

    转载网址:http://www.cnblogs.com/lovebread/archive/2009/11/23/1609122.html 1.按字节读取文件内容 2.按字符读取文件内容 3.按行读取 ...

  8. 【转载】ArrayList使用LastIndexOf方法查找最后一个符合条件的元素位置

    在C#的编程开发中,ArrayList集合是一个常用的非泛型类集合,在ArrayList集合中如果需要查找最后一个符合条件的元素所在的位置,可以使用ArrayList集合的LastIndexOf方法, ...

  9. 【转载】C#使用InsertRange方法往ArrayList集合指定位置插入另一个集合

    在C#的编程开发中,ArrayList集合是一个常用的非泛型类集合,ArrayList集合可存储多种数据类型的对象.在实际的开发过程中,我们可以使用InsertRange方法在ArrayList集合指 ...

随机推荐

  1. LeetCode-Pathcing Array

    Given a sorted positive integer array nums and an integer n, add/patch elements to the array such th ...

  2. 160628、利用Oracle rownum让表排序字段值连续

    利用Oracle rownum让表排序字段值连续 1.需求说明 表(eval_index)中有字段如下: 表字段 描述 说明 ID 主键 GROUP_ID 分组编号 SORT_NUM 排序序号 按照分 ...

  3. StackExchange.Redis性能调优

    大家经常出现同步调用Redis超时的问题,但改成异步之后发现错误非常少了,但却可能通过前后记日志之类的发现Redis命令非常慢. PS: 以后代码都在Windows bash中运行,StackExch ...

  4. 封装IP池和用户代理相应的类(python3)

    一.middlewares.py源代码: # -*- coding: utf-8 -*- # 导入随机模块 import random # 导入有关IP池有关的模块 from scrapy.contr ...

  5. <2014 05 10> Android平台开发攻略

    1.标准SDK开发: IDE: Eclipse Netbeans Language: Java 2.标准NDK+SDK开发: IDE: Eclipse Language: Java(JNI) C/C+ ...

  6. delphi中String 和 动态静态数组

    默认string类型为ansiString:有编译开关控制 shortString: strShort : shortString; strShort 大小256字节,可根据sizeof()计算出,s ...

  7. Struts2 框架的值栈

    1. OGNL 表达式 1.1 概述 OGNL(Object Graphic Navigation Language),即对象图导航语言; 所谓对象图,即以任意一个对象为根,通过OGNL可以访问与这个 ...

  8. CSS 快速入门

    特点: CSS 将网页内容和显示样式进行分离,提高了显示效果的功能. CSS 和 html 相结合的四种方式: style 属性的方式 每个 html 标签中都有一个 style 样式属性, 该属性的 ...

  9. 海量数据存储之nosql教程(转)

    add by zhj: 不错的系列,作者介绍了NoSQL数据库,并重点研究了Memcached和Redis,不知道后续是否还有其它NoSQL数据库的文章 海量数据存储之nosql教程之-01基础理论 ...

  10. leetcode -day 15 Distinct Subsequences

    1.  Distinct Subsequences  Given a string S and a string T, count the number of distinct subsequen ...