Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为登录用户iOS/iPhone使用预加载用户信息_Ios_Iphone_Objective C_Core Data_Entity Relationship - Fatal编程技术网

如何为登录用户iOS/iPhone使用预加载用户信息

如何为登录用户iOS/iPhone使用预加载用户信息,ios,iphone,objective-c,core-data,entity-relationship,Ios,Iphone,Objective C,Core Data,Entity Relationship,我是iPhone应用程序开发的新手。在我的应用程序中,我的用户要么必须登录,要么通过钥匙链服务自动登录 我目前正在尝试允许我的用户添加朋友。在我的实体Player中,我添加了一个与之相反的关系,名为friend 要创建此函数并将其作为iAction链接到我的Add按钮,我考虑如下: -(void)addFriendFunction: (NSManagedObject *)user (UITextField *)newfriendName { //fetches friend using fri

我是iPhone应用程序开发的新手。在我的应用程序中,我的用户要么必须登录,要么通过钥匙链服务自动登录

我目前正在尝试允许我的用户添加朋友。在我的实体Player中,我添加了一个与之相反的关系,名为friend

要创建此函数并将其作为iAction链接到我的Add按钮,我考虑如下:

-(void)addFriendFunction: (NSManagedObject *)user (UITextField *)newfriendName {

//fetches friend using friendName
NSManagedObject *newfriend = [self findFriendUsingFriendName:newfriendName];

//Add the friend to the user (owner of the phone)

NSSet *userFriends = [user friends]
[userFriends addObject:newfriend];

}
我不太确定这个代码是否正确,也请指导我。我的主要问题是,如何提取用户(登录用户),以便将其传递到该函数中。我必须在登录期间初始化单例吗?还是有更好的方法可以让我做到?例如,我是否可以简单地使用钥匙链或任何我不知道的预制工具提取它


谢谢大家!

您的方法似乎还可以,其余部分用于预填充数据,您可以期待以下链接

苹果开发者教程真的解释得很好

使用钥匙链,可以帮助您解决问题。:)

如果您还需要其他帮助,请发表评论

可能重复的帖子我可以访问iPhone上的钥匙链吗


您也可以从这里下载演示项目

为什么不使用
NSUserDefaults

登录时存储
userId

[[NSUserDefaults standardUserDefaults] setInteger:userId forKey:@"userId"];
[[NSUserDefaults standardUserDefaults] synchronize];
当应用程序启动时,检查
用户ID是否存在于
NSUserDefaults

if([[NSUserDefaults standardUserDefaults] integerForKey:@"userId"]>0)
{
    //Load other resources against userId. and do what ever you want with your logged in user.
}