I add following code:
- (IBAction)done {
// Return any edited content to the host app.
// This template doesn't do anything, so we just echo the passed in items.
NSURL *url = [NSURL URLWithString:@"lister://today"];
[self.extensionContext openURL:url completionHandler:^(BOOL success) {
NSLog(@"fun=%s after completion. success=%d", __func__, success);
}];
[self.extensionContext completeRequestReturningItems:self.extensionContext.inputItems completionHandler:nil];
}
after I create the Action Extension target. But it can not work.
My purpose is that: when user view a photo in Photos.app (the iOS's default Photos.app or called gallery), and he click the share button to launch our extension view. We can transfer the image from Photos.app to my own app and deal or upload the image in my app.
I also try "CFBundleDocumentTypes" but it also can not work.
Any help will be appreciated.
Not every app extension type supports "extensionContext openURL".
I tested on iOS 8 beta 4 and found Today extension supports it, but keyboard extension does not.
This is by design. We don't want Custom Actions to become app launchers.
Following code works on Xcode 8.3.3, iOS10, Swift3 and Xcode 9, iOS11, Swift4 without any compiler warnings:
Make sure your app supports Universal Links, otherwise it will open the link in browser. More info here: https://developer.apple.com/library/content/documentation/General/Conceptual/AppSearch/UniversalLinks.html
Try this code.
Solution for the latest iOS SDK 10.2. All previous solutions use deprecated api. This solution is based on searching UIApplication UIResponder of the hosting application (This app which create execution context for our extension). The solution can only be provided in Objective-C because there is a 3 arguments method to invoke and this is impossible to do with
performSelector:
methods. To invoke this not deprecated methodopenURL:options:completionHandler:
we need to use NSInvocation instance which is unavailable in Swift. The provided solution can be invoked from Objective-C and Swift (any version). I need to say that I don't know yet if provided solution will be valid for apple review process.UIViewController+OpenURL.h
UIViewController+OpenURL.m
From Swift 3 You can execute this only if Your view controller is in view hierarchy. This is the code how I'm using it:
It seems to be a bug, because docs say:
I reported it today: http://openradar.appspot.com/17376354 You should dupe it, if you have some free time.