我做了一个带有登录功能的IOS应用程序。我使用 ASIHTTPRequest 来检查用户是否存在于 MySQL 数据库中。一切正常,但我想通过其他视图控制器传递用户 ID 或在应用程序的其他部分检索它。
有人可以推动我朝着正确的方向前进,如何以最好、最安全的方式做到这一点?
这是我向 PHP 脚本发出 POST HTTP 请求的方式:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"*SOME_URL*"]];
在回调中,我可以检索用户 ID,但我想将此 ID 存储在应用程序的内存中以供进一步使用。
Thanks.
您可以存储userId
in the AppDelegate
.
声明一个userId
财产在AppDelegate.h
使用以下代码:
@property (nonatomic, strong) NSString *userId
然后将其合成AppDelegate.m
使用以下代码:
@synthesize userId;
然后你可以使用userId
从应用程序中的任何位置。添加导入AppDelegate
在你想要使用的类中userId
, 如下:
#import "AppDelegate.h"
要检索userId
使用以下代码:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *userId = [appDelegate userId];
并设置userId
使用以下代码:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setUserId:YouValueRetrievedByInternetOrWhateverYouWant];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)