zoukankan      html  css  js  c++  java
  • iOS archiveRootObject 归档失败问题

    归档失败问题出在路径上,NSHomeDirectory()

    NSString *stringPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0];

        stringPath = [stringPath stringByAppendingPathComponent:@"a.txt"];            // 成功

        NSLog(@"1111%@",stringPath);

        NSString * path2 = [NSHomeDirectory() stringByAppendingPathComponent:@"a.txt"];      // 失败,注意这里用的是NSHomeDirectory()

        NSLog(@"2222%@",path2);

        BOOL suc = [NSKeyedArchiver archiveRootObject:@"aaaa" toFile:path2];

        if (suc) {

            NSLog(@"user 归档成功!");

        }else{

            NSLog(@"user 归档失败!");

        }

    1.NSHomeDirectory()  :  

    /var/mobile/Containers/Data/Application/28C6BFE8-4E50-4DEB-9E55-18F0815CDBC5

    2.[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0] :

    /var/mobile/Containers/Data/Application/F7DC1040-57CB-4104-8AD6-55E9F287FC38/Documents/

    看一下,

    NSHomeDirectory() + /fileName   =  /var/mobile/Containers/Data/Application/28C6BFE8-4E50-4DEB-9E55-18F0815CDBC5/fileName  归档失败

    [...NSDocumentDirectory...] +/fileName  = /var/mobile/Containers/Data/Application/F7DC1040-57CB-4104-8AD6-55E9F287FC38/Documents/fileName 成功 

    红色区域是问题所在

  • 相关阅读:
    Python·Jupyter Notebook
    CNN(卷积神经网络)、RNN(循环神经网络)、DNN(深度神经网络)概念区分理解
    tensorflow学习
    语料库
    资源 | 数十种TensorFlow实现案例汇集:代码+笔记
    Tensorlayer
    利用 TFLearn 快速搭建经典深度学习模型
    十分钟搞定pandas
    利用python进行数据分析之pandas入门
    Pandas
  • 原文地址:https://www.cnblogs.com/fengmin/p/5015688.html
Copyright © 2011-2022 走看看