小编kri*_*ish的帖子

Swift3 Xcode 8:'none'不可用:使用[]构造一个空选项集; 我该怎么办?

UIUserNotificationType.none在ViewController.swift上使用了Swift3,我得到了这个错误:'none'不可用user []来构造一个空的选项集; 这是我的代码:

func updateUI() {
       let currentSettings = UIApplication.shared.currentUserNotificationSettings

    if currentSettings?.types != nil {

        if currentSettings!.types == [UIUserNotificationType.badge, UIUserNotificationType.alert] {

            textField.isHidden = false

            button.isHidden = false

            datePicker.isHidden = false

        }
        else if currentSettings!.types == UIUserNotificationType.badge {

            textField.isHidden = true

        }
        else if currentSettings!.types == UIUserNotificationType.none {

            textField.isHidden = true

            button.isHidden = true

            datePicker.isHidden = true

        }

    }

}
Run Code Online (Sandbox Code Playgroud)

ios swift usernotifications

7
推荐指数
1
解决办法
4271
查看次数

如何在按下通知操作时运行URL?

我创建了一个包含两个操作的通知.我的一个动作叫做"取消",而另一个叫做"呼叫".如何使"调用"操作运行我添加到代码中的注释中的URL.这是我的代码:

  func notificationFires(){

    /**
     URL Code:

     if let url = URL(string: "tel://") {
     UIApplication.shared.open(url, options: [:])
     }


**/

    let call = UNNotificationAction(identifier:"call", title:"Call", options:[.foreground])
    let cancel = UNNotificationAction(identifier: "cancel", title: "Cancel", options: [.destructive ])
    let category = UNNotificationCategory(identifier: "category", actions: [call, cancel], intentIdentifiers: [], options: [])
    UNUserNotificationCenter.current().setNotificationCategories([category])

    let notification = UILocalNotification()
    notification.category = "category"
    // 2

    notification.soundName = UILocalNotificationDefaultSoundName
    notification.fireDate = datePicker.date

    // 3
    if textField.text == "" {

        notification.alertBody = "You have a call right now!"

    }
    else{

        notification.alertBody …
Run Code Online (Sandbox Code Playgroud)

xcode swift swift2 swift3

5
推荐指数
1
解决办法
772
查看次数

标签 统计

swift ×2

ios ×1

swift2 ×1

swift3 ×1

usernotifications ×1

xcode ×1