dismiss share extension custom viewcontroller

后端 未结 2 1376
悲&欢浪女
悲&欢浪女 2021-01-11 22:55

I am trying to create a custom view controller to be used with a share extension. Everything works, but I don\'t know how to dismiss the custom view controller. Basically I

相关标签:
2条回答
  • 2021-01-11 23:36

    For those who are trying to do this from viewDidLoad, you need to set a small timer, otherwise it won't work:

    override func viewDidLoad() {
        super.viewDidLoad()
        Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: #selector(self.didSelectPost), userInfo: nil, repeats: false)
      }
    
    0 讨论(0)
  • 2021-01-11 23:50

    You should end your sharing extensions work with one of these two calls:

    self.extensionContext!.completeRequestReturningItems(nil, completionHandler: nil)
    
    self.extensionContext!.cancelRequestWithError(NSError())
    

    Apples share extension docs

    updated for swift 4:

    self.extensionContext!.completeRequest(returningItems: nil, completionHandler: nil)
    
    self.extensionContext!.cancelRequest(withError:NSError())
    
    0 讨论(0)
提交回复
热议问题