extensionContext openURL doesn't work since beta5

In beta4 we could do [extensionContext openURL] to open external links in safari. In beta5 is doesn't work anymore.


Anyone is having that issue?

Accepted Reply

The expected behavior is that the iMessage extension can only open URLs in their parent apps. If that's not something that works for you, please file bug reports with details of what you need.

Replies

With regard to getting users into the App Store for iMessage, have a look at the "Linking to Your Product Page" section of this page: https://developer.apple.com/app-store/imessage-app-submissions/ for how to construct URLs that would take the user to your product page.

Thanks pdm for the better URL link.


But I assume it's still not possible currently to have our iMessage standalone app launch a store URL. This is what I just tried and it didn't work:


            let urlString = "https://itunes.apple.com/us/app/<appname>/id<number>?ls=1&mt=8&app=messages"
            if let urlToOpen = URL(string: urlString), let messageExtension = self.extensionContext {
                messageExtension.open(urlToOpen, completionHandler: nil)
            }


So I have filed a radar request to get at least this functionality from iMessages to get to its app store. As discussed above, this did seem to work in earlier betas but now you can only open URL in parent app.


Unless I'm missing something?

I noticed that too. If someone has cracked this cookie, mind sharing the code? Thanks

i'm trying to open an appstore link as well and failing.. but I've downloaded an app called "Word Swipe" which seemed to have figured it out. They present icons that when tapped take me to the appstore app. I'll contact support for the app and see if I can coax any details

Feels like it will be the scene from the Godfather when all the other bosses sit down and ask him to share the senators and judges in his pocket.


Go get 'em! (downloading Word Swipe now)

Hah.. I sent a tweet to their support account. We'll see

You got me trying stuff again. Now that I know its do-able! Let crack this.

Actually, I think I found it. I have the store loading into a view controler (not opening the external app yet).. but I'm close


http://stackoverflow.com/questions/433907/how-to-link-to-apps-on-the-app-store/32008404#32008404

I tried that too, but ran into issues. Looks like Word Swipe isn't loading a view controller within the extension. Could be wrong though. Checking that link you sent for anything new. Thanks

True, Word Swipe is definatly launching the AppStore app, which this isn't doing. But it might work for my needs. I'll keep hammering at it

I think what I tried was a webview taking up the full screen. It would open the initial link, but then I couldn't click any links from within. Definitely strange.

Good call, this works better than anything else I'd tried so far....


  func openStoreProductWithiTunesItemIdentifier(identifier: String) {
   
     self.requestPresentationStyle(.expanded)
        let storeViewController = SKStoreProductViewController()
        storeViewController.delegate = self
   
        let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
        storeViewController.loadProduct(withParameters: parameters) { [weak self] (loaded, error) -> Void in
       
      
            if loaded {
           
                /
                self?.present(storeViewController, animated: true, completion: nil)
            }
        }
    }

    func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
        viewController.dismiss(animated: true, completion: nil)
    }


Usage...


openStoreProductWithiTunesItemIdentifier(identifier: "1135990335")


And as the Stack link notes, you'll need to import StoreKit and add SKStoreProductViewControllerDelegate as the delete.


Some of the top of the store gets cut off seems to be the only issue so far!

Yes, I'm at the same place you are. I'm now looking into making it a child viewcontroller of the main one and shrink the size down so the header isn't cut off. Currently crashing but I'll post if I get that working.

Ok. I've got it sized correctly using contraints (I'm still using objectivec.. but you get the idea).


- (void)openStoreProductViewControllerWithITunesItemIdentifier:(NSInteger)iTunesItemIdentifier {
   
    SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init];
    storeViewController.delegate = self;
    NSNumber *identifier = [NSNumber numberWithInteger:iTunesItemIdentifier];
    NSDictionary *parameters = @{ SKStoreProductParameterITunesItemIdentifier:identifier };
   
    [storeViewController loadProductWithParameters:parameters
                                   completionBlock:^(BOOL result, NSError *error) {
                                       if (result) {
                                          
                                           [self requestPresentationStyle:MSMessagesAppPresentationStyleExpanded];
                                          
                                           storeViewController.view.frame = self.view.bounds;
                                           [self.view addSubview:storeViewController.view];
                                          
                                           storeViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
                                           [storeViewController.view.leftAnchor constraintEqualToAnchor:self.view.leftAnchor].active = YES;
                                           [storeViewController.view.rightAnchor constraintEqualToAnchor:self.view.rightAnchor].active = YES;
                                           [storeViewController.view.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor].active = YES;
                                           [storeViewController.view.bottomAnchor constraintEqualToAnchor:self.bottomLayoutGuide.topAnchor].active = YES;
                                          
                                          
                                           [storeViewController didMoveToParentViewController:self];
                                         }
                                       else NSLog(@"SKStoreProductViewController: %@", error);
                                   }];
   
}

Awesome, you beat me to it. I'll post the swift version when I get it converted. Thanks!