在ios10中添加自定义本地通知 - swift 3

时间:2016-06-15 07:57:20

标签: swift swift3 uilocalnotification ios10 unusernotificationcenter

我尝试添加自定义本地通知,但我只是通过我的操作获取股票通知:

enter image description here

我的故事板看起来像这样(标准模板):

enter image description here

我有一个UNNotificationExtensionCategory设置为awesomeNotification的扩展名(在Info.plist中)。此扩展程序的基础也是Notification Content的{​​{1}}模板。

在我的app委托中,我有这个:

iOS - Application Extension

在我的主应用程序的viewcontroller中,我有以下操作来触发它:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let center = UNUserNotificationCenter.current()

    let actions = [UNNotificationAction.init(identifier: "Hey", title: "Yo", options: UNNotificationActionOptions.foreground)]

    let category = UNNotificationCategory(identifier: "awesomeNotification", actions: actions, minimalActions: actions, intentIdentifiers: [], options: [])
    center.setNotificationCategories([category])

    center.requestAuthorization([.alert, .sound]) { (granted, error) in
    }

    return true
}

修改

所以它适用于iPhone 6s / 6s +,非常奇怪的行为: enter image description here

1 个答案:

答案 0 :(得分:5)

更新:从iOS 10测试版2开始,3D预触摸设备上也会提供丰富的通知。下拉常规通知即可查看。

确保您在iPhone6s / iPhone6s以及模拟器/设备上进行测试,它似乎不适用于3D前触摸设备。

在iPhone6模拟器上,尝试点击并向下拖动您获得的股票通知,您应该会看到自定义用户界面。