douchun2158 2011-10-29 13:46
浏览 48
已采纳

这个步骤的下一步是用php webservice登录iphone

i developing an iphone app with login to mysql db by php api , after i checking the authentication of username and password that will redirect to the home screen.

The problem that i need to pass the user id to the home screen to fetch over API an other data with the logged in user, So how can i do that .. if anybody has an experience in that issue please help..

this code about the login process after checking the validity of user over PHP API:

if([serverOutput isEqualToString:@"OK"] ){
    Home *home = [[[Home alloc] initWithNibName:@"Home" bundle:nil] autorelease];
    home.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:home animated:YES];
    [serverOutputLabel release];
} else {
    UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Invalid Login"
    message:@"Username or Password Incorrect"
    delegate:self 
    cancelButtonTitle:@"OK" 
    otherButtonTitles:nil, nil];
    serverOutputLabel.text=serverOutput;
    [alertsuccess show];
    [alertsuccess release];
    [serverOutputLabel release];
}
  • 写回答

1条回答 默认 最新

  • 普通网友 2011-10-29 14:01
    关注

    You can store user id in NSUSerDefautls and if its a valid your keep them save in NSUserDefaults otherwise clean them if it's an invalid user.

    So next time when you want to send request to server, get User id from NSUserDefaults and append it to api.

    NSUserDefaults *defaults= [NSUserDefaults standardUserDefaults];
    [defaults setObject:YOUR_USER_ID forKey:@"UserId"];
    

    to get user id from defaults.

     NSString *userId = [defaults objectForKey:@"UserId"];
    

    Also clear the defaults when user log out and on authentication failure.

    [defaults setObject:@"" forKey:@"UserId"];
    

    also see this

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效