Rachit
Rachit

Reputation: 842

How to check the “Allow Full Access” is enabled in iOS 10?

How to check the “Allow Full Access” is enabled in iOS 10?

This method is not working in iOS 10

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

Upvotes: 1

Views: 1191

Answers (3)

Jeet
Jeet

Reputation: 1040

Here's an objective c version

-(BOOL) checkIfFullAccessEnabled {
NSOperatingSystemVersion osv = [NSProcessInfo processInfo].operatingSystemVersion;
if(osv.majorVersion >= 10) {
    UIPasteboard *pb = [UIPasteboard generalPasteboard];
    if(pb.hasStrings || pb.hasURLs || pb.hasColors || pb.hasImages) {
        return YES;
    }
    else {
        NSString *ustr = pb.string;
        pb.string = @"777-TEST-123";
        if(pb.hasStrings) {
            pb.string = ustr;
            return YES;
        }
        else {
            return NO;
        }
    }
}
else if([UIPasteboard generalPasteboard] != nil) {
    return YES;
}
else {
    return NO;
}

}

Upvotes: 2

Mike
Mike

Reputation: 818

I've been testing this today and it appears that you don't have to set something on the pasteboard to verify that you have access. All you need to do is test to see if something is on the pasteboard. Of course if the pasteboard happens to be completely empty then it's not an exhaustive test so in that case you do need to set something, but then you've already ruled out anything being replaced. Here's what I came up with

func checkFullAccess() -> Bool
{
    if #available(iOSApplicationExtension 10.0, *) {
        let pasty = UIPasteboard.general
        if pasty.hasURLs || pasty.hasColors || pasty.hasStrings || pasty.hasImages {
            return true
        } else {
            pasty.string = "TEST"
            if pasty.hasStrings {
                pasty.string = ""
                return true
            }
        }
    } else {
        // Fallback on earlier versions
        var clippy : UIPasteboard?
        clippy = UIPasteboard.general
        return clippy != nil
    }
    return false
}

In my tests I found that all the checks (hasString, hasImages, etc) would return false even with content on the pasteboard with full access turned off. If they all return false then it could be truly empty so you try setting something in that case. If it wasn't empty then you don't have access and you won't be replacing anything, if it was empty and you do have access then the text will be placed there and you can return it to it's previous state.

HTH, Mike

Upvotes: 1

Randy
Randy

Reputation: 2358

User @user979686 posted a solution in the following thread but I have not tested this.

https://stackoverflow.com/a/38903406/4792451

Posting the code here for clarity.

let originalString = UIPasteboard.general.string
UIPasteboard.general.string = "TEST"
if UIPasteboard.general.hasStrings
{
    UIPasteboard.general.string = originalString
    hasFullAccess = true
}
else
{
     hasFullAccess = false
}

Upvotes: 1

Related Questions