我从图像选择器中取出图像并将图像上传到网络服务,我有一个图像网址。我使用用户默认值保存图像,如下所示:
-(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;
}
这里的配置文件pic值是imgStr,它是从web服务获得的图像。
当我尝试在不同的viewcontroller中检索imageurl时,userdefault的值为null,因为它显示错误。
NSString *urlstring = [[NSUserDefaults standardUserDefaults] objectForKey:@"image_Str"];
NSLog(@"urlstring is %@",urlstring);
此处urlstring为null,错误为错误:请求失败:未找到(404)
答案 0 :(得分:0)
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);