Chris Wagner
Chris Wagner

Reputation: 21003

UIPasteboard.generalPasteboard in Action Extension

I've been working on an Action Extension since beta 1. It is a URL shortner via bitly.com. When the URL is shortened it is copied to the user's pasteboard

UIPasteboard.generalPasteboard().URL = shortUrl

This was working fine the last time I checked in beta 5. As of GM it seems we no longer have access to the pasteboard?

po UIPasteboard.generalPasteboard().URL

Returns nil in scenarios that I know there is something there, and when I verify that shortUrl indeed contains a value, the assignment is ignored. Printing UIPasteboard.generalPasteboard().URL always returns nil while debugging the extension.

Was access to the pasteboard removed? It seems to be a silent failure if so.

I have also reproduced this in Objective-C, so it is not a Swift issue.

Update

I tried this in an extension that has user interface (there are two types of action extensions, those without and those with). For those with UI, the pasteboard works as expected. So this seems isolated to action extensions without UI.

I also reported a bug on this.

Update 2

I believe this to be a bug, Apple closed my radar as a duplicate.

Upvotes: 4

Views: 1745

Answers (1)

Derek
Derek

Reputation: 1021

I'm running into the same issue as well. I'm using it in objective-C though. Tried the pasteboard in it's simplest form and still nothing.

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString:@"copied string"];

The above code works fine in the containing app though.

Update: For those still searching for an answer and wanting to use the pasteboard with the custom keyboard extension, I came across this post: iOS8 Custom Keyboard - Copy & Paste to UIPasteboard

You will need to allow BOTH full access in your plist file and allow full access in the keyboard settings in the Settings.app.

Upvotes: 4

Related Questions