简体   繁体   English

我可以通过应用扩展在主 iOS 应用中执行任务吗?

[英]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.

相关问题 如何与我的主应用程序和 iOS 应用程序的应用程序扩展正确共享 Amplify 框架? - How can I properly share the Amplify framework with my Main App and my App Extension for an iOS app? 我可以在iOS应用中将参数传递给main吗? - Can I pass parameters to main in an iOS app? 从扩展目标访问主App类 - iOS - Accessing main App class from extension target - iOS 从iOS Safari共享扩展打开主应用 - Open the main app from a iOS Safari Share Extension iOS:在应用程序处于后台时执行上传任务 - iOS: Perform upload task while app is in background 如何打开我的 SwiftUI 应用程序并使用 Siri Intent Extension 中的 NSUseractivity 执行功能? - How can I open my SwiftUI app and perform a function using NSUseractivity from within Siri Intent Extension? 在Swift中,如何将永久变量从主iOS应用传递到扩展程序(例如,今天的扩展程序,自定义键盘) - In Swift, how would I pass a permanent variable from the main iOS app to an extension (e.g. today extension, custom keyboard) App Extension iOS9:如何从共享视图向我的应用程序发送字符串/ URL? - App Extension iOS9: How can I send a string / URL from the share view to my the app? 如何使用应用程序扩展中的 IPC 将信息异步发送到 iOS 上的包含应用程序? - How can I use IPC from an app extension to asynchronously send information to the containing app on iOS? NSInvalidUnarchiveOperationException 仅在 iOS 扩展中引发,而不是在主应用程序中 - NSInvalidUnarchiveOperationException raised only in iOS extension, not main app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM