如何在iOS共享扩展程序中正式处理未经身份验证的用户?

编程入门 行业动态 更新时间:2024-10-11 23:24:27
本文介绍了如何在iOS共享扩展程序中正式处理未经身份验证的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

也就是说,Apple规定的惯用方法是什么? 对于任何建议,请说明应如何做和/或提供指向官方指南的链接.这应该是一个足够常见的情况,但我只能找到解决方法.

That is, what is an idiomatic way to do this that is prescribed by Apple? For any suggestion, please explain HOW that should be done and/or provide a link to official guides. This should be a common enough scenario, but I was only able to find workarounds.

从另一端解决这个问题,我知道 UserDefaults(suiteName:)

Approaching this from the other end, I know that UserDefaults(suiteName:) and Keychain services can be used from the containing app to share information about the authenticated user with the extension, but what if the user installs the app and just jumps right into trying to share content using its extension without ever signing in (or up)?

  • 要求用户登录包含的应用程序吗?(在自定义视图中?默认情况下,扩展名是模态的.)

  • Ask user to sign in in the containing app? (In a custom view? Extensions are modal by default.)

    扩展中的重新实现身份验证?(或通过自定义框架共享吗?这可能吗?)

    Re-implement authentication in extension? (Or shared via custom framework? Is this possible?)

    要切换到包含应用程序然后再返回吗?除了今日"扩展程序,似乎不支持此功能,但是文档已被使用解决方法(SO线程: 1 , 2 , 3 ).

    Switch to containing app and then back? This doesn't seem to be supported except in Today extension, but the mechanism described in the docs have been used for workarounds (SO threads: 1, 2, 3).

    第2项的(丑陋)示例实现在此答案中使用Firebase.

    An (ugly) sample implementation of item 2 in this answer using Firebase.

    推荐答案

    我找不到任何官方指南,但是以下解决方案确实有效,并且在App Store中也被接受.底线可能恰好是:(1)不应该崩溃,(2)应该能够通过审核过程.

    I couldn't find any official guidelines, but the solution below did work and also got accepted in App Store. Probably the bottom line is exactly that: (1) it shouldn't crash and (2) should be able to go through the review process.

    具有[FirebaseUI身份验证[( github/firebase/FirebaseUI-iOS的解决方案):

    The solution with [FirebaseUI authentication[(github/firebase/FirebaseUI-iOS):

    相关代码部分:

    import UIKit import Social import Firebase import FirebaseAuthUI class ShareViewController: SLComposeServiceViewController { var authUI: FUIAuth? /* Using shared container to communicate between extension and containing app. Keychain would probably work too. */ let defaults = UserDefaults.init(suiteName: "your-app-group")! override func presentationAnimationDidFinish() { /* stackoverflow/questions/37910766/ */ if FirebaseApp.app() == nil { FirebaseApp.configure() } self.authUI = FUIAuth.defaultAuthUI() self.authUI?.delegate = self if self.defaults.bool(forKey: "userLoggedIn") == false { let fuiSignin = FUIPasswordSignInViewController( authUI: FUIAuth.defaultAuthUI()!, email: nil) let navController = UINavigationController(rootViewController: fuiSignin) self.present(navController, animated: true) } } /* FirebaseAuthUI delegate to handle sign-in */ extension ShareViewController: FUIAuthDelegate { func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) { if error != nil { fatalError() } if user != nil { self.defaults.set(true, forKey: "userLoggedIn") } } }

    成功登录也会通过共享容器记住(即,打开包含应用程序不会要求登录).

    Successful sign in also gets remembered via the shared container (i.e., opening the containing app won't ask for login).

    github项目中的相关提交: github/society-对于盲人/Access-News-Reader-iOS/commit/e752b1c554f79ef027818db35c11fceb1ae817e0

    The relevant commit in the github project: github/society-for-the-blind/Access-News-Reader-iOS/commit/e752b1c554f79ef027818db35c11fceb1ae817e0

    问题

    我第一次运行它,表格出现了,但是不接受任何输入.做了Product > Clean和Product > Clean Build Folder ...,重新启动了Xcode和Simulator,它开始工作了.它还可以在旧的iPad(iOS 10.3.3)上运行.

    The first I ran it, the forms appeared, but wouldn't accept any input. Did Product > Clean and Product > Clean Build Folder ..., restarted Xcode and the Simulator, and it worked. It also worked on an old iPad (iOS 10.3.3).

  • 更多推荐

    如何在iOS共享扩展程序中正式处理未经身份验证的用户?

    本文发布于:2023-11-28 12:22:37,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1642377.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:身份验证   正式   程序   用户   如何在

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!