且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS7到iOS8应用程序文件的迁移

更新时间:2023-02-03 09:17:04


应用程序容器的文件系统布局在磁盘上已更改。

而不是依靠硬编码的目录结构,使用
NSSearchPathForDirectoriesInDomains 函数或
URLForDirectory:inDomain:appropriateForURL:create:error:方法
NSFileManager 使用 URLForDirectory:inDomain:appropriateForURL:create:error:
方法 NSFileManager
$ b

 NSFileManager * yourFileManager = [NSFileManager defaultManager]; 
NSURL * urlForSomeDirectory = [yourFileManager URLForDirectory:NSDocumentDirectory inDomain:NSAllDomainsMask appropriateForURL:nil create:YES error:nil];

如果您正在使用此方法,那么您不需要你可以用 NSDocumentDirectory 。 //developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/index.html#//apple_ref/c/tdef/NSSearchPathDirectory\">其他常量 。你可能还想用 NSError ** 来代替最后一个参数。



奖金问题:它不应该,但是你永远不知道。


I am currently testing my app on iOS8. Everything works well on pure iOS8 but I am struggling with the App files migration from iOS7 that will occur for users when iOS8 will be publicly released. As my application uses several "Standard Directories" (Documents, Application Support, ...), I would like to be sure the migration will be smooth.

The application filesystem structure has changed on iOS8 (read iOS beta 4 Release note and the file system programming guide).

When iOS8 will be installed on a device, I guess all previously installed applications and all related files (in Documents, Application Support, ...) will be re-organized to match the new structure.

Do you guys have any clues about the (exhaustive) list of changes that will occur during iOS7 to iOS8 upgrade ? I can't find any documentation on this subject. Is there a way to test/simulate a migration of an iOS7 application sandbox to the new iOS8 sandbox structure ?

Thanks

BONUS question: does the application GUID change when the OS upgrades ?

The file system layout of app containers has changed on disk.

Rather than relying on hard-coded directory structure, use the NSSearchPathForDirectoriesInDomains function or the URLForDirectory:inDomain:appropriateForURL:create:error: method of the NSFileManager class.

Using the URLForDirectory:inDomain:appropriateForURL:create:error: method of NSFileManager:

NSFileManager *yourFileManager = [NSFileManager defaultManager];
NSURL *urlForSomeDirectory = [yourFileManager URLForDirectory:NSDocumentDirectory inDomain:NSAllDomainsMask appropriateForURL:nil create:YES error:nil];

If you are currently using this method, then you don't need to change a thing.

You can replace NSDocumentDirectory with many other constants. You may also want to substitute a NSError ** for the last parameter if you would like to catch an error.

The bonus question: It shouldn't, however you never know.