[英]Share User Object between App and App Extension in iOS8
I am using Pocket API and authenticating the user on the app. 我正在使用Pocket API并在应用程序上对用户进行身份验证。
While in the extension i want to use the logged in user to run methods to call various endpoints. 在扩展程序中,我想使用登录的用户来运行方法来调用各种端点。 The only option to share data between the app and its extension is NSUserDefaults as I see on various threads but NSUserDefaults cannot save NSObjects of logged in user. 正如我在各种线程上看到的那样,在应用程序及其扩展名之间共享数据的唯一选项是NSUserDefaults,但NSUserDefaults无法保存已登录用户的NSObjects。
How can I use the logged in user in the Extention ? 如何在扩展中使用已登录的用户?
I am logging the user like this in the app.. 我正在应用程序中记录这样的用户。
[[PocketAPI sharedAPI] loginWithHandler: ^(PocketAPI *API, NSError *error){
if (error != nil)
{
NSlog (@"User Logged In");
}
}];
}
and in the extension i want to use : 在扩展名中我想使用:
[[PocketAPI sharedAPI] saveURL:url handler: ^(PocketAPI *API, NSURL *URL,
NSError *error){
if(error){
NSLog(@"There was an error in saving the URL : %@ ", [error description]);
}else{
NSLog(@"URL was saved successfully ");
}
}];
how do i dynamically save the [PocketAPI sharedAPI] to use any method on either side? 如何动态保存[PocketAPI sharedAPI]在任一端使用任何方法? How can i share the same instance of the object 我如何共享对象的相同实例
For saving user credentials better store in Keychain, it is more secure and you can access in extension also. 为了更好地保存用户凭据,将其存储在钥匙串中,它更加安全,您也可以扩展访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.