`
zjjzmw1
  • 浏览: 1356123 次
  • 性别: Icon_minigender_1
  • 来自: 开封
社区版块
存档分类
最新评论

ios 本地存储,防止被苹果拒绝。

    博客分类:
  • iOS
阅读更多

 

现在如果用userdefault 存储大数据的话,会自动同步的icloud里面,不会通过审核的。

所以应该存到NSCachesDirectory里面,另外,Document,Library 也不行的。

用的时候很简单,两个方法,,,,只要新建一个字典或者数组就行了。

 

 

+(BOOL)saveFileToLoc:(NSString *) fileName theFile:(id) file{

//    SJBLog(@"%@",file);

    NSString *Path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    //NSString *urlString2 = @"http://i.meijika.com/business/home.txt";

    NSString *CachePath = [fileName stringByReplacingOccurrencesOfString: @"/"withString: @"_"];

    NSString *filename=[Path stringByAppendingPathComponent:CachePath];

//    SJBLog(@"%@",fileName);

    NSFileManager *fileManager = [NSFileManagerdefaultManager];

    if (![fileManager fileExistsAtPath:filename]) {

        if (! [fileManager createFileAtPath:filename contents:nil attributes:nil]) {

            SJBLog(@"createFile error occurred");

        }

    }

   return  [file writeToFile:filename atomically:YES];

}

 

+(BOOL) getFileFromLoc:(NSString*)filePath into:(id)file {

    NSString *Path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];

 

    NSString *CachePath = [filePath stringByReplacingOccurrencesOfString: @"/"withString: @"_"];

    NSString *filename=[Path stringByAppendingPathComponent:CachePath];

    

    if ([file isKindOfClass:[NSMutableDictionary class]]) {

         [file setDictionary: [NSMutableDictionarydictionaryWithContentsOfFile:filename]];

    }else if ([file isKindOfClass:[NSMutableArray class]]) {

         [file addObjectsFromArray: [NSMutableArrayarrayWithContentsOfFile:filename]];

    }

//   kNSLog(@"file===%@",file);

    if ([file count]==0) {

        return NO;

    }

    returnYES;

 

}

 

 ///存储数据。。。。

        NSData *tempData = UIImageJPEGRepresentation(tempImage, 1.0f);

        self.myDic = [NSMutableDictionary dictionaryWithObject:tempData forKey:self.myURL];

 

        [ViewControllerFactorysaveFileToLoc:self.myURLtheFile:self.myDic];

 

if ([ViewControllerFactorygetFileFromLoc:self.myURLinto:self.myDic]) {

        [self showSubway];

 

    }

 

1
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics