PhoneGap / Cordova 1.5 iOS“不备份”文件属性 [英] PhoneGap / Cordova 1.5 iOS "do not back up" file attribute

查看:142
本文介绍了PhoneGap / Cordova 1.5 iOS“不备份”文件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Apple网站上的开发人员文件: https:// developer.apple.com/library/ios/#qa/qa1719/_index.html


从iOS 5.0.1开始已经引入了新的不备份文件属性,允许开发人员清楚地指定应该备份哪些文件。 (com.apple.MobileBackup)


我想知道PhoneGap / Cordova是否支持这个功能,存储一些未在iCloud上备份的离线数据(可以下载或以其他方式重新创建,但用户希望在离线时可靠地可用的数据)。



Persistance (LocalFileSystem.PERSISTENT - http://docs.phonegap .com / en / 1.5.0 / phonegap_file_file.md.html#LocalFileSystem ),但似乎没有办法确保保存的文件没有备份到iCloud。

解决方案

我仍然在PhoneGap / Cordova中找到一个解决方案,但作为一个临时工作...



在我的AppDelegate init中:

  NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 

//获取文档目录
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * formularyPath = [documentsDirectory stringByAppendingPathComponent:@OfflineData];

if(![[NSFileManager defaultManager] fileExistsAtPath:formularyPath])
[[NSFileManager defaultManager] createDirectoryAtPath:formularyPath withIntermediateDirectories:NO attributes:nil error:nil];

//防止iCloud备份
u_int8_t b = 1;
setxattr([formularyPath fileSystemRepresentation],com.apple.MobileBackup,& b,1,0,0);

不要忘记 #importsys / xattr.h / p>

这会在文档下创建一个新文件夹,并设置无备份属性。



使用持久化本地文件存储选项的PhoneGap和保存在新子目录中的文件将不会备份。


According to the developer documentation on Apple's website: https://developer.apple.com/library/ios/#qa/qa1719/_index.html

Starting in iOS 5.0.1 a new "do not back up" file attribute has been introduced allowing developers to clearly specify which files should be backed up. (com.apple.MobileBackup)

I'm wondering if this is supported in PhoneGap / Cordova, as I want to be able to store some offline data (data that can be downloaded or otherwise recreated, but that the user expects to be reliably available when offline) that is not backed up on iCloud.

Persistance is clearly documented (LocalFileSystem.PERSISTENT - http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html#LocalFileSystem) on the PhoneGap website, but there seems to be no way of ensuring a saved file is not backed up to the iCloud.

解决方案

I'm still holding out for a solution within PhoneGap / Cordova but as a temporary work around...

In my AppDelegate init:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

// Get documents directory
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *formularyPath = [documentsDirectory stringByAppendingPathComponent:@"OfflineData"];

if (![[NSFileManager defaultManager] fileExistsAtPath:formularyPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:formularyPath withIntermediateDirectories:NO attributes:nil error:nil];

// Prevent iCloud backup
u_int8_t b = 1;
setxattr([formularyPath fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);

Don't forget #import "sys/xattr.h"

This creates a new folder under documents and sets the no backup attribute.

You can then save your files in PhoneGap using the persisted local file store option and files saved in your new subdirectory will not be backed up.

这篇关于PhoneGap / Cordova 1.5 iOS“不备份”文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆