Swift: Unable to open url from extensioncontext in uiCollectionView?

866 views Asked by At

Alright Im building a message extension app with a uicollectionview with header and footer. After several tries I learned why I wasn't able to open a url from the message controller using normal syntax - because its an extension it should use:

  let url: URL = URL(string: "http://www.google.com")!
    self.extensionContext?.open(url, completionHandler: { (success: Bool) in
        print("hi")
    })

And this COMPILES but does not work in the MessageViewController file. I don't know why, but then in my

class FooterCollectionReusableView: UICollectionReusableView {

this does not compile even. I get the error enter image description here

How can I open a url from my footer in my message extension? Is this possible?

1

There are 1 answers

2
Samantha On

It looks like you're calling extensionContext on your FooterCollectionReusableView. extensionContext is a property of UIViewController, so if you want to reference it from a view you would need to keep a reference to the parent view controller's extensionContext, or create a protocol that would allow you to call the parent view controller to do whatever you need to be done with the extensionContext.