简体   繁体   中英

Make iOS Action Extension get notified that the Host app became active

I have an Application and an accompanying Action Extension. The extension's main purpose is to upload a file from any calling app into the URL provided by the main app.

The workflow is:

  1. In the main app, user selects an URL from the list

  2. In any app, iCloud Drive for example, user can choose any file, tap the Share button, choose the accompanying Action Extension, which will do the upload to previously selected URL

The extension's ViewController has "Change" button, which opens the main app. So that user can switch to the main app, choose another URL and return back to the host app (which has the extension still active there).

在此处输入图片说明

I'm trying to figure out how the extension, which is purely just a ViewController and doesn't have direct access to host app's lifecycle could be notified that the host app became active again. So that the extension could pick up the newly chosen link.

I don't have direct access to the host's appDelegate methods, neither viewWillAppear get called when extension's view becomes active again.

Any ideas?

Answering my own question: there is at least one way to do it - using NotificationCenter, described in this answer to the "Why does viewWillAppear not get called..." question.

If someone has a better idea - I will be glad to experiment with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM