如何把苹果登录相关业务逻辑从 ViewController 中封装出去
-
在工程实现中,我们接入苹果登录的页面,一般是登录页面,很自然地,像苹果官方 Demo 示例的一样,我们在登录页面中直接写代码调起 ASAuthorizationViewController,并把当前的登录 ViewController 作为 ASAuthorizationViewController 对象的 delegate 与 presentationContextProvider。
-
当然,我们都会想把这部分业务逻辑封装到一个单独的类里,姑且就叫 AppleSignService。从而把 AppleSignService 作为 ASAuthorizationViewController 对象的 delegate 与 presentationContextProvider。在原来的登录页面,我们只需要初始化 AppleSignService 的对象即可。
-
然而,这样实现的问题是,无法得到 delegate 的回调。经过多方尝试,发现要把 AppleSignService 设计为单例才可以获得正常回调。
-
所以,这是苹果内部的某种实现引起的问题,记录一下,有懂的大神,还请不吝赐教,多谢!!