[英]Can I perform a task in Main iOS app from the app Extension?
I have an app extension for Sharing (Share Extension) and when a user selects my app to share an image, my app will send that image to a server.我有一个用于共享的应用扩展(共享扩展),当用户选择我的应用来共享图像时,我的应用会将该图像发送到服务器。
The problem is that the server requires an authenticated identity (AWS Cognito) to send the object to the server.问题是服务器需要经过身份验证的身份 (AWS Cognito) 才能将 object 发送到服务器。 Since I cannot share Authentication from my main app to my extension and I don't want to have the user sign in every time they want to share, I'm stuck.由于我无法将身份验证从我的主应用程序共享到我的扩展程序,并且我不想让用户每次想要共享时都登录,所以我被卡住了。
I can see this being done with messaging apps where a user sends a message from a share extension.我可以看到这是通过消息传递应用程序完成的,用户从共享扩展程序发送消息。 I'm not sure how they achieve this.我不确定他们是如何做到这一点的。 Since the user is not asked to login again in the extension, somehow the credentials are either being shared with the extension or the app is momentarily launched to perform that upload while remaining in the background (not sure this is possible).由于不要求用户在扩展程序中再次登录,因此凭据以某种方式与扩展程序共享,或者应用程序暂时启动以执行该上传,同时保持在后台(不确定这是否可能)。
So my question is what is the approach I should be using.所以我的问题是我应该使用什么方法。 Should the extension somehow be directing the main app to upload the image or should I figure a way of sharing the access tokens with the extension in a secure way and accessing them without any user action?扩展程序是否应该以某种方式指示主应用程序上传图像,或者我应该想办法以安全的方式与扩展程序共享访问令牌并在没有任何用户操作的情况下访问它们?
The solution is to setup a shared container for the app & the extension, please see "Sharing data with your containing app" section in this article: https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#:~:text=To%20enable%20data%20sharing%2C%20use,App%20to%20an%20App%20Group .解决方案是为应用程序和扩展设置一个共享容器,请参阅本文中的“与包含的应用程序共享数据”部分: https://developer.apple.com/library/archive/documentation/General/Conceptual/ ExtensibilityPG/ExtensionScenarios.html#:~:text=To%20enable%20data%20sharing%2C%20use,App%20to%20an%20App%20Group 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.