Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow Full Access check in keyboards iOS10

Recently iOS has an update of iOS 10 & there are certain changes for developers one of the change is now we can't check allow full access the way we did previously is given below

-(BOOL)isOpenAccessGranted{
   return [UIPasteboard generalPasteboard];
 }

I searched the latest Developer Guide for UIPasteboard, but was unable to solve it. Did any one has a proper solution for this.

like image 579
iYoung Avatar asked Sep 17 '16 05:09

iYoung


2 Answers

iOS11 and above is easy.

iOS10 Solution: Check all the copy-able types, if one of them is available, you have full access otherwise not.

-- 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)
    }
}
like image 101
Ahmet Akkök Avatar answered Sep 23 '22 20:09

Ahmet Akkök


I have fixed this issue. iOS 10.0 and 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
        }

    }

}

Use like this:-

if (isOpenAccessGranted())
{
   print("ACCESS : ON")
}
else{
   print("ACCESS : OFF")
}
like image 21
Mitul Marsoniya Avatar answered Sep 24 '22 20:09

Mitul Marsoniya