

- #Didselectpost swift share extension how to#
- #Didselectpost swift share extension full#
- #Didselectpost swift share extension code#
> pkd : assigning plug-in SHARE_EXTENSION_BUNDLE_ID(1.0) to plugin sandbox I checked the logs from the iPad I’m working on and I get this: I can see my AIR app icon in applications list when I hit the Share button, but the popup does not show up. Thanks for that great tutorial, it helped me a lot at some point, but it seems I cannot manage to make it work correctly. Var fileList : Array = argList.split( "," ) įor each ( var filePath : String in fileList ) b) We should now be left with a comma separated list of file paths like this: Log( "No arguments after the url scheme" ) We expect the string to be split into exactly two parts: Var argList : Array = _argStr.split( "://" ) The app was probably invoked for another reason and with another URL scheme, get out of here. If ( -1 = _argStr.indexOf( APP_SHARE_URL_SCHEME ) ) We expect a single argument in the following format: Private function processInvokeArguments( _argStr : String ) : Array Now let the host app know we are done, so that it unblocks its UI: to invoke your app before it's dismissed: The delay is important here, otherwise the UIWebView won't have time Now get the UIWebView to load the request, which will launch the app: and the paths to the photos you want to share: this will use the custom url scheme of your app Prepare the URL request for the UIWebView: UIWebView * webView = initWithFrame: CGRectMake( 0, 0, 0, 0 ) ] Instantiate a UIWebView that's so tiny it won't show on the screen: openURL doesn't work for any extension, but the Today one, As we'll be creating UI, make sure the calls happen on the main thread:ĭispatch_async ( dispatch_get_main_queue(), ( void ) invokeApp: ( NSString * ) invokeArgs You will add them one by one, starting with addImagePathToArgumentList:
#Didselectpost swift share extension code#
You have probably noticed that the code above calls a couple of functions that have not been defined yet: saveImageToAppGroupFolder, addImagePathToArgumentList and invokeApp.
#Didselectpost swift share extension full#
For a full list of type constants follow this link. For other types of information you will need to modify the code in didSelectPost to first check if the desired type has been selected and then to handle it.
#Didselectpost swift share extension how to#
This example shows you how to share JPEG attachments.You will instead let the host app know we’re done in invokeApp, which you will implement in Step 3. Not too long, though, as the host app’s UI will be blocked until you make one of these calls to let it know that the extension has done its job. What completeRequestReturningItems does is pass UI control back to the host app (Camera Roll) and you want to hold on to that control for a little longer, so you can use a trick to launch our AIR app. The call that was initially done in didSelectPost, completeRequestReturningItems (or its alternative ) is no longer your friend, so we’ve commented it out.This is why we go through the more tedious task of loading the whole image and then saving it to a place the AIR app can access. Having the path to an image in Camera Roll will not be of much use to our AIR app, as it won’t have permission to access the media folder directly.Tip: To get the direct path to a shared file, use the following completion handler instead: completionHandler: ^ ( NSURL * url, NSError * error ). If we have reached the last attachment, it's time to hand control to the app: Now add the path to the list of arguments we'll pass to the app: so we temporary copy them to a folder which both the extension and the app can access: The app won't be able to access the images by path directly in the Camera Roll folder, NSLog( was an error retrieving the attachments: error ) [ itemProvider loadItemForTypeIdentifier: ( NSString * ) kUTTypeJPEGĬompletionHandler: ^ ( UIImage * image, NSError * error ) M_inputItemCount = įor ( NSItemProvider * itemProvider in item.attachments ) Reset the counter and the argument list for invoking the app:
