Allow Full Access check in keyboards iOS10
Asked Answered
T

6

6

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.

Truditrudie answered 17/9, 2016 at 5:20 Comment(1)
I have same issue.Lens
U
5

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)
    }
}
Uneasy answered 17/2, 2017 at 21:29 Comment(1)
Good answer so farLuik
L
4

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")
}
Lens answered 18/9, 2016 at 5:12 Comment(11)
Don't you think setting "TEST" string to UIPastebord general will replace the preexisting text of user. Is this an optimal solution?Truditrudie
It's work I have used UIPasteboard.generalPasteboard().string instead of UIPasteboard.general.hasStringsUttasta
@mitul I have tried this but it is pasting TEST in OTT textfield which is not the proper solution.Truditrudie
This use for check allow full access on or off. Now i change some code then you did not get pest just review edited code.Lens
@mitulmarsonia This is still not optimal as it will not paste TEST, instead it will override the already copied data of user with "". Hope you understand.Truditrudie
@Truditrudie Just check before you copy data.Example if you want check before copy data Access on/off then just use this function and after you put your copy code.Lens
@mitulmarsonia: Completely agree that this is a workaround but from a user's persective this is not expected as user will never like the data to be vanished which he has copied for his future use.Truditrudie
@Truditrudie You are also right i also think about that but now i use this way because i have don't know other solution for swift 3.0. If in future we get then i will sure update answer. Thanks.Lens
I am also reading the documents of apple for this change but still this should not be used for apps, that is what I believe.Truditrudie
If you want temporary then you can used because we have not any other options so.Lens
Crashes the keyboard extension if UIImage has been pasted to UIPasteboard.Platter
T
4

For friends, searching solution in Objective-C, Here it is

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.: This is just a workaround

Truditrudie answered 29/9, 2016 at 14:28 Comment(1)
Hi,Can you explain i have tried the code you mention,But it always gives Yes only. Even if i remove my 3rd party keyboard.Coaptation
B
0

Tested on iOS 10 Swift 3.0 and iOS 9

Use #available(iOS 10.0, *) instead of #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)
    }
}
Botchy answered 28/9, 2016 at 17:1 Comment(0)
E
0

Swift 3

static func isOpenAccessGranted() -> Bool {
    if #available(iOS 10.0, iOSApplicationExtension 10.0, *) {
        let value = UIPasteboard.general.string
        UIPasteboard.general.string = "checkOpenedAccess"

        let hasString = UIPasteboard.general.string != nil
        if let _ = value, hasString {
            UIPasteboard.general.string = value
        }
        return hasString
    }
    else {
        return UIPasteboard(name: UIPasteboardName(rawValue: "checkOpenedAccess"), create: true) != nil
    }
}
Eruct answered 31/10, 2016 at 0:55 Comment(0)
S
0

A bit hacky, but it works:

Swift 5

static func isOpenAccessGranted() -> Bool {
    let inputVC = UIInputViewController()
    return inputVC.hasFullAccess
}
Sruti answered 22/1, 2020 at 6:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.