如何在 mgtwitterengine api 中保留给定的密码

发布于 2024-11-17 19:57:21 字数 760 浏览 1 评论 0原文

我想将用户给出的密码保存在变量中。从哪里获取密码值。我查看代码,但它只包含用户名。我在我的应用程序中使用 MGTwitterengine api。这是在控制台上打印数据的函数。

-(void)setUsername:(NSString *)newUsername password:(NSString *)newPassword
{
     NSLog(@"uset sername %@ and password %@",newUsername,newPassword);
     ...
}

我在所有函数中进行调试,但我看到该函数在登录后正在运行。但这在密码值中打印空,尽管用户名打印得很好。实际上我必须追踪用户的所有推文价值。我浏览了 MGTwitterEngine。有一段代码,但是需要写用户名和密码。

这是代码

MGTwitterEngine *twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self]; 

[twitterEngine setUsername:@"username" password:@"password"]; 
// Get updates from people the authenticated user follows. 

NSString *connectionID = [twitterEngine getFollowedTimelineFor:nil since:nil startingAtPage:0];

请帮我如何保留密码?

I want to keep password which is given by user in a variable. Where to get password value. I look in code but it is containing only username. I am using MGTwitterengine api in my application. Here is the function which is printing data on console.

-(void)setUsername:(NSString *)newUsername password:(NSString *)newPassword
{
     NSLog(@"uset sername %@ and password %@",newUsername,newPassword);
     ...
}

I debug in all function but I saw this function is running after loggedin. But this is printing null in password value although username is printing well. Actually I I have to trace all tweet value of user. I went through MGTwitterEngine. There is a block of code but it is necessary to write username and password.

Here is the code

MGTwitterEngine *twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self]; 

[twitterEngine setUsername:@"username" password:@"password"]; 
// Get updates from people the authenticated user follows. 

NSString *connectionID = [twitterEngine getFollowedTimelineFor:nil since:nil startingAtPage:0];

Please help me how to keep password ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅 2024-11-24 19:57:21

阅读开发者文档,它提供了您所需的所有信息,就像简单的事情一样这。回到问题,有几种方法可以保存这些数据。

NSUserDefaults:您可以使用此类保存用户名密码,如下所示:

[[NSUserDefaults sharedUserDefaults] setObject:username forKey:@"username"];
[[NSUserDefaults sharedUserDefaults] setObject:username forKey:@"password"];
[[NSUserDefaults sharedUserDefaults] synchronize];

一旦您再次需要此数据,请调用它:

NSString*username = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
NSString*password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];

OR :

NSDictionary:如果你不想依赖NSUserDefaults,你可以将登录数据保存在NSDictionary中并保存将其添加到您的沙箱中。它的工作原理如下:

NSMutableDictionary*loginDictionary = [[NSMutableDictionary alloc] init];
[loginDictionary setObject:username forKey:@"username"];
[loginDictionary setObject:password forKey:@"password"];
[loginDictionary writeToFile://Your Path Here atomically:NO];

[loginDictionary release];

然后,一旦您再次需要数据,请从文件中读取:

NSMutableDictionary*loginDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile://Your Path];

NSString*username = [loginDictionary objectForKey:@"username"];
NSString*password = [loginDictionary objectForKey:@"password"];

[loginDictionary release];

希望它有帮助!

Read the developer documentation, it provides all the info you need for something as easy as this. Back to the question, there're a couple of ways how you can save this data.

NSUserDefaults: You can save the username and password using this class like this:

[[NSUserDefaults sharedUserDefaults] setObject:username forKey:@"username"];
[[NSUserDefaults sharedUserDefaults] setObject:username forKey:@"password"];
[[NSUserDefaults sharedUserDefaults] synchronize];

Once you need this data again, call it:

NSString*username = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
NSString*password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];

OR:

NSDictionary: If you don't want to rely on NSUserDefaults, you can save the login data in a NSDictionary and save it to your sandbox. This works like this:

NSMutableDictionary*loginDictionary = [[NSMutableDictionary alloc] init];
[loginDictionary setObject:username forKey:@"username"];
[loginDictionary setObject:password forKey:@"password"];
[loginDictionary writeToFile://Your Path Here atomically:NO];

[loginDictionary release];

Then, once you need the data again, read from file:

NSMutableDictionary*loginDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile://Your Path];

NSString*username = [loginDictionary objectForKey:@"username"];
NSString*password = [loginDictionary objectForKey:@"password"];

[loginDictionary release];

Hope it helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文