我已经从图像拾取器中获取了图像并将图像上传到Web服务,并且我使用了一个图像URL。
-(void)postSignupService {
[NewJsonHelperClass postExecuteWithParams:@"signup" secondParm:[self signUpParams] onCompletion:^(NSDictionary *json){
if ([[json valueForKey:@"status"] isEqualToString:@"success"]) {
NSDictionary *dataDict =[NSDictionary new];
dataDict =[json valueForKey:@"user"];
[[NSUserDefaults standardUserDefaults] setObject:@"sucess" forKey:@"LoginStatus"];
[[NSUserDefaults standardUserDefaults] setObject:[dataDict valueForKey:@"_id"] forKey:@"user_Id"];
[[NSUserDefaults standardUserDefaults] setObject:[dataDict valueForKey:@"userName"] forKey:@"userName"];
[[NSUserDefaults standardUserDefaults] setObject:[dataDict valueForKey:@"password"] forKey:@"Password"];
[[NSUserDefaults standardUserDefaults] setObject:[dataDict valueForKey:@"email"] forKey:@"email_Id"];
[[NSUserDefaults standardUserDefaults] setObject:[dataDict valueForKey:@"profile_pic"] forKey:@"image_Str"];
NSLog(@"datadict is %@",dataDict);
SelectFoodVC *selectVc = [appDelegateRef.storyBoard instantiateViewControllerWithIdentifier:@"SelectFoodVC"];
[self.navigationController pushViewController:selectVc animated:YES];
// TabBarController *tabVc = [appDelegateRef.storyBoard instantiateViewControllerWithIdentifier:@"TabBarController"];
// [self.navigationController pushViewController:tabVc animated:YES];
}
else{
[reUse showAlertWithTitle:[json valueForKey:@"status"] message:[json valueForKey:@"user"] thirdParam:self];
}
}];
}
-(NSDictionary *)signUpParams {
NSMutableDictionary *params =[NSMutableDictionary new];
params[@"userName"] =self.userNameTf.text;
params[@"email"] =self.emailTf.text;
params[@"password"] =self.passwordTf.text;
NSLog(@"imgstr is %@",imgStr);
params[@"profile_pic"] =imgStr;
return params;
}
此处profile pic value是imgstr,它是从Web服务中获得的imageUrl。
当我尝试在不同的ViewController中检索imageUrl时,用户默认值的值是无效的,因为它显示了错误。
NSString *urlstring = [[NSUserDefaults standardUserDefaults] objectForKey:@"image_Str"];
NSLog(@"urlstring is %@",urlstring);
这里的urlstring为null,错误是错误:请求失败:找不到(404(
NSString *str = [NSString stringWithFormat:@"http://swiftdeveloperblog.com/wp-content/uploads/2015/07/1.jpeg"];
NSURL *url = [NSURL URLWithString:str];
[[NSUserDefaults standardUserDefaults]setURL:url forKey:@"URL"];
[[NSUserDefaults standardUserDefaults]synchronize];
NSString *getURL = [[NSUserDefaults standardUserDefaults]URLForKey:@"URL"];
NSLog(@"url is %@",getURL);