天天看點

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

完。