天天看点

ios8 notification in swift

AppDelegate.swift

ios8 notification in swift

ViewController.swift

ios8 notification in swift

运行,按下 command + L / command + H 使模拟器处于锁屏状态/主屏幕,效果如下

ios8 notification in swift
ios8 notification in swift

下面处理 First Action 和 Second Action 的点击事件:

还是在AppDelegate.swift中,

ios8 notification in swift

然后在ViewController.swift 中接收通知并处理,

ios8 notification in swift

具体的效果自己运行一下就可以看到了,这里就不贴出来了。

另外,在模拟器的 Settings ->  Notifications -> Notifications ->  可以设置通知的弹出样式,有3种样式可以选择(先运行一下程序然后在Settings中才可以看到Notifications选项)

ios8 notification in swift

完。