gpt4 book ai didi

swift3 - 在我的应用程序中单击按钮时打开手机设置

转载 作者:行者123 更新时间:2023-12-02 11:51:29 24 4
gpt4 key购买 nike

我最近升级到 Xcode 8 并将代码转换为 Swift 3。我正在制作一个自定义键盘(扩展),它在 iOS 9 之前工作得很好,但我在 iOS 10 中遇到了一些问题。

  1. 自定义键盘的容器应用包含一个按钮,可引导用户进入键盘设置以添加键盘

问题:此按钮单击在 iOS 10 中不起作用,即用户不会定向到设置。我已经在我的项目中配置了 URL 方案并尝试了以下代码:

@IBAction func btnGetStarted(_ sender: AnyObject) {

let settingsUrl = URL(string: UIApplicationOpenSettingsURLString)
if let url = settingsUrl {
UIApplication.shared.openURL(url)
}
}

也尝试过:

@IBAction func btnGetStarted(_ sender: AnyObject) {

if let settingsURL = URL(string:"prefs:root=General&path=Keyboard/KEYBOARDS") {
UIApplication.shared.openURL(settingsURL)
}
}
  • 自定义键盘还包含表情符号图像。用户需要在设置中启用“允许访问”才能使用表情符号图像。如果用户未启用“允许访问”,则他无法使用表情符号图像。如果未启用“允许访问”,并且用户尝试单击表情符号,则会弹出一个提示框,告诉用户转到设置并启用“允许访问”。
  • 问题:当应用在 iOS 10 中运行时,此 Toast 不会弹出

    toast 代码:

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){

    let pbWrapped: UIPasteboard? = UIPasteboard.general

    if let pb = pbWrapped {
    if currentKeyboard == XXXXXX.emoji {
    if let data = UIImagePNGRepresentation(dataEmoji[(indexPath as NSIndexPath).row]) {
    pb.setData(data, forPasteboardType: "public.png")

    self.makeToast(pasteMessage, duration: 3.0, position: .center)
    }
    }

    } else {
    var style = ToastStyle()
    style.messageColor = UIColor.red
    style.messageAlignment = .center
    //style.backgroundColor = UIColor.whiteColor()

    self.makeToast("To really enjoy the keyboard, please Allow Full Access in the settings application.", duration: 8.0, position: .center, title: nil, image: UIImage(named: "toast.png"), style: style, completion: nil)
    }
    }

    我确实在 stackoverflow 上查看了一些解决方案,但没有一个对我有用,正如我之前所说,我的应用程序在除 iOS 10 之外的所有版本上都运行得很好。请问有人可以帮我吗?

    最佳答案

    Swift 3 iOS 10

    let settingsUrl = NSURL(string:UIApplicationOpenSettingsURLString) as! URL
    UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)

    关于swift3 - 在我的应用程序中单击按钮时打开手机设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39659720/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com