1

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];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Rachit
  • 814
  • 9
  • 19
  • That code won't compile. You can't return `UIPasteboard` when `BOOL` is the return type. – rmaddy Sep 09 '16 at 18:51
  • That's not a useful response. I think we all know what the OP intended here. @Rachit, Have you found a solution yet? – Randy Sep 13 '16 at 02:21

3 Answers3

2

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;
}

}
codercat
  • 22,873
  • 9
  • 61
  • 85
Jeet
  • 1,030
  • 2
  • 10
  • 20
1

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
}
Community
  • 1
  • 1
Randy
  • 2,270
  • 1
  • 15
  • 24
  • This is not an optimal solution as a developer because it is forcefully setting TEST string on UIPasteboard & then checking. This can also happen if UIPasteboard already has user's sensitive content on it then that data will be replaced by TEST. So that is not good. – iYoung Sep 17 '16 at 06:15
  • I agree, I am merely stating one solution that posted by another user. Do you know of a better way to do this? – Randy Sep 23 '16 at 02:26
  • I am also searching the best way. – iYoung Sep 23 '16 at 06:22
1

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

Daniel Saidi
  • 6,079
  • 4
  • 27
  • 29
Mike
  • 788
  • 10
  • 27