最近iOS有iOS 10及更新版本开发人员有一些变化,现在我们无法检查允许完全访问权限我们之前的做法如下所示
-(BOOL)isOpenAccessGranted{
return [UIPasteboard generalPasteboard];
}
我搜索了最新的Developer Guide for UIPasteboard,但无法解决。有没有人有适当的解决方案。
答案 0 :(得分:5)
iOS11及以上版本很简单。
iOS10解决方案:检查所有可复制的类型,如果其中一个可用,则您具有完全访问权限,否则不会。
- Swift 4.2 -
override var hasFullAccess: Bool
{
if #available(iOS 11.0, *){
return super.hasFullAccess// super is UIInputViewController.
}
if #available(iOSApplicationExtension 10.0, *){
if UIPasteboard.general.hasStrings{
return true
}
else if UIPasteboard.general.hasURLs{
return true
}
else if UIPasteboard.general.hasColors{
return true
}
else if UIPasteboard.general.hasImages{
return true
}
else // In case the pasteboard is blank
{
UIPasteboard.general.string = ""
if UIPasteboard.general.hasStrings{
return true
}else{
return false
}
}
} else{
// before iOS10
return UIPasteboard.general.isKind(of: UIPasteboard.self)
}
}
答案 1 :(得分:4)
我已经解决了这个问题。 iOS 10.0 和 Swift 3.0
func isOpenAccessGranted() -> Bool {
if #available(iOSApplicationExtension 10.0, *) {
UIPasteboard.general.string = "TEST"
if UIPasteboard.general.hasStrings {
// Enable string-related control...
UIPasteboard.general.string = ""
return true
}
else
{
UIPasteboard.general.string = ""
return false
}
} else {
// Fallback on earlier versions
if UIPasteboard.general.isKind(of: UIPasteboard.self) {
return true
}else
{
return false
}
}
}
像这样使用: -
if (isOpenAccessGranted())
{
print("ACCESS : ON")
}
else{
print("ACCESS : OFF")
}
答案 2 :(得分:4)
对于朋友,在Objective-C中搜索解决方案,这是
NSOperatingSystemVersion operatingSystem= [[NSProcessInfo processInfo] operatingSystemVersion];
if (operatingSystem.majorVersion>=10) {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"Hey";
if (pasteboard.hasStrings) {
pasteboard.string = @"";
return true;
}
else
{
pasteboard.string = @"";
return false;
}
}
else
{
return [UIPasteboard generalPasteboard];
}
P.S。:这只是一种解决方法
答案 3 :(得分:0)
在iOS 10 Swift 3.0和iOS 9上测试
使用#available(iOS 10.0, *)
代替#available(iOSApplicationExtension 10.0, *)
func isOpenAccessGranted() -> Bool {
if #available(iOS 10.0, *) {
var originalString = UIPasteboard.general.string
if(!(originalString != nil)){
originalString = ""
}
UIPasteboard.general.string = "Test"
if UIPasteboard.general.hasStrings {
UIPasteboard.general.string = originalString
return true
}else{
return false
}
}else{
return UIPasteboard.general.isKind(of: UIPasteboard.self)
}
}
答案 4 :(得分:0)
Swift 3
BitConverter.ToSingle
答案 5 :(得分:0)
有点hacky,但是可以用:
快捷键5
static func isOpenAccessGranted() -> Bool {
let inputVC = UIInputViewController()
return inputVC.hasFullAccess
}