3."CallExtension"与宿主程序之间的数据共享

"callExtension"虽然作为一个拓展程序,但是他与宿主程序拥有两个不同的沙盒路径,所以数据无法共享!但是iOS 8.0 以后,苹果提供了一个叫做Appgroups的数据共享操作.

开启AppGroups

Paste_Image.png

AppGroups数据读写

  • 读取数据:
//获取文件路径
    NSURL *fileUrl = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"AppGroups名称"];
    NSString *filePath = [fileUrl.absoluteString substringFromIndex:(@"file://".length)];
    NSString *filePathIdentification = [filePath stringByAppendingString:@"存储的文件名称"];
//读取数据
    NSArray *txlArr = [NSArray arrayWithContentsOfFile:filePathIdentification];
  • 存入数据
//获取文件路径
    NSURL *fileUrl = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"AppGroups名称"];
    NSString *filePath = [fileUrl.absoluteString substringFromIndex:(@"file://".length)];
    NSString *filePathIdentification = [filePath stringByAppendingString:@"存储的文件名称"];
//存入数据
    NSArray *callArr = [NSArray new];
    BOOL success = [callArr writeToFile:filePathIdentification atomically:YES];
  • PS:�AppGroups存储数据是一次最好不要超过20条,否则会存储失败.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容