在我的应用程序中单击按钮时打开电话设置 [英] Open phone settings when button is clicked in my app

查看:65
本文介绍了在我的应用程序中单击按钮时打开电话设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级到Xcode 8,并将代码转换为Swift3.我正在制作一个自定义键盘(扩展名),该键盘在iOS 9之前都可以正常工作,但是在iOS 10中我遇到了两个问题.

I recently upgraded to Xcode 8 and converted my code to Swift 3. I am making a custom keyboard (extension) which worked perfectly fine till iOS 9, but i am facing a couple of issues in 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)
 }
}

  1. 自定义键盘还包含表情符号图像.用户需要启用设置中的允许访问"才能使用表情符号图像.如果用户未启用允许访问",则他将无法使用表情符号图像.如果未启用允许访问",并且用户尝试单击表情符号,则会弹出一个吐司,提示用户进行设置并启用允许访问".

问题:在iOS 10中运行该应用程序时不会弹出此吐司

烤面包的代码:

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以外的所有版本上都可以正常使用.有人可以帮我吗?

I did check out few solutions on stackoverflow but none of them worked for me, as I said before my app works perfectly fine on all versions except iOS 10. Please can someone help me out?

推荐答案

Swift 3 iOS 10

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

这篇关于在我的应用程序中单击按钮时打开电话设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆