1

Is it possible to redirect a user back to my app from my share extension (after finishing the posting/other action)?

I couldn't get UIApplication.sharedApplication() to work - method was unavailable.

Any ideas if this is possible/if Apple even allows it?

Nimrod007
  • 9,825
  • 8
  • 48
  • 71
royherma
  • 4,095
  • 1
  • 31
  • 42
  • What share extension are you using? Is it `UIActivityViewController` or you have created your custom? – iYoung May 11 '16 at 02:19
  • share extension, as in a separate target - and it is the Share Extension. Here is a link for reference https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Share.html – royherma May 11 '16 at 03:06
  • 4
    Possible duplicate of [Share Extension to open Host App](http://stackoverflow.com/questions/27506413/share-extension-to-open-host-app) – Bogdan Farca Oct 09 '16 at 19:05

2 Answers2

2

Actually this is possible by searching for UIApplication up in the responder chain and invoking openURL on it, like described in this response : https://stackoverflow.com/a/28037297/554203.

This is the code that works for XCode 8, Swift 3.0 and iOS10 (again, extracted from Julio Bailon's response above):

let url = NSURL(string:urlString)
let context = NSExtensionContext()
context.open(url! as URL, completionHandler: nil)

var responder = self as UIResponder?

while (responder != nil){
    if responder?.responds(to: Selector("openURL:")) == true{
        responder?.perform(Selector("openURL:"), with: url)
    }
    responder = responder!.next
}
Community
  • 1
  • 1
Bogdan Farca
  • 3,856
  • 26
  • 38
0

As of iOS 9.3, this does not seem to be possible for a Share Extension.

royherma
  • 4,095
  • 1
  • 31
  • 42