网络04

作者: xwf_code | 来源:发表于2016-11-01 19:16 被阅读0次

导入框架后使用MD5加密

 NSString *encodePsd =[self.passwordTextField.text md5String];

使用框架保存账号密码到用户设置

 // 保存用户名
    [[NSUserDefaults standardUserDefaults] setObject:self.nameTextField.text forKey:@"name"];
 // 需求 : 密码保存到本地,需要加密和能够解密 (钥匙串)
    /*
     参数1 : 你要保存到钥匙串的密码
     参数2 : APP的唯一标识符,为哪个APP保存密码
     参数3 : 为哪个APP里面的哪个账号保存密码
     
     提示 : 因为XCode8需要开启钥匙串的权限;XCode7不需要
     */
    BOOL isSaved = [SSKeychain setPassword:self.passwordTextField.text forService:[NSBundle mainBundle].bundleIdentifier account:self.nameTextField.text];
    NSLog(@"%d",isSaved);

匹配的读取用户设置

// 读取用户名
    self.nameTextField.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"name"];
// 从钥匙串中读取密码
    /*
     参数1 : 读取哪个APP的密码
     参数2 : 读取哪个APP的哪个账号的密码
     */
    NSString *decodePsd = [SSKeychain passwordForService:[NSBundle mainBundle].bundleIdentifier account:self.nameTextField.text];
    
    // 读取密码
    self.passwordTextField.text = decodePsd;

将字典或数组转换成为json二进制文件的两种方法

-(NSData *)json1
{
    NSDictionary *dict=@{@"姓名":@"徐文逢"};
    NSData *json1=[NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
    NSLog(@"%@",json1);
    NSDictionary *d=[NSJSONSerialization JSONObjectWithData:json1 options:0 error:NULL];
    NSLog(@"%@",d);
    return json1;
}
-(NSData *)json2
{
    xwf *x=[xwf new];
    x.name=@"徐文逢";
    
    NSDictionary *dict=[x dictionaryWithValuesForKeys:@[@"name"]];
    NSData *data=[NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
    NSDictionary *d=[NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
    NSLog(@"%@",d);
    return data;
}

相关文章

网友评论

      本文标题:网络04

      本文链接:https://www.haomeiwen.com/subject/tbemuttx.html