iOS 8: Bundle Path Changes

ios 8: Bundle path changes

Refer Technical Note 2406 by Apple

The breaking change is

Beginning in iOS 8, the Documents and Library directories are no
longer siblings of your application's bundle.

Don't store full path/URL to your documents. Store the file name and always generate full path/URL with recommended approach.

Get the DocumentsDirectory URL

// Returns the URL to the application's Documents directory.
- (NSURL *)applicationDocumentsDirectory {
{
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

Then you get path out of url and append the file name to generate full path.

Handling ios Bundle Path Changes

I will take this approach as it is the one used in the Big Nerd Ranch book:

https://github.com/ninjinkun/ios-programming-the-big-nerd-ranch-guide/blob/master/Homepwner/Homepwner/Model/ImageStore.m

http://www.bignerdranch.com/

Document directory path change when rebuild application

iOS 8 onwards, Absolute url to app's sandbox changes every time you relaunch the app. Hence you should never save the absolute url of the video. Save the name of the video and recreate the url every time you relaunch the app.

  let pathComponent = "pack\(self.packID)-\(selectRow + 1).mp4"
let directoryURL: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let folderPath: URL = directoryURL.appendingPathComponent("Downloads", isDirectory: true)
let fileURL: URL = folderPath.appendingPathComponent(pathComponent)

Once you have fileURL look for the file and you will find the file downloaded in previous launch.

iOS creates a new Sandbox for app every time user launches the app. Hence absolute URL will very. But iOS will take care of setting up all the folders and contents inside the Sandbox as it was earlier. So though base url of SandBox change, relative url's of all the content will be remained intact.

Hence its advised never to save absolute url to any folder :) Hope it helps

iOS setting.bundle issue with iOS 8 at simulator

It is normal now at Xcode 6 beta 7.@@

How do I get all resource paths in my bundle recursively in iOS?

I got this working using the code posted by @rekle as a starting point. The trick is to use NSDirectoryEnumerator, which will do this recursively. Here's the function I wrote in case anyone needs it.

- (NSArray *)recursivePathsForResourcesOfType:(NSString *)type inDirectory:(NSString *)directoryPath{

NSMutableArray *filePaths = [[NSMutableArray alloc] init];

// Enumerators are recursive
NSDirectoryEnumerator *enumerator = [[[NSFileManager defaultManager] enumeratorAtPath:directoryPath] retain];

NSString *filePath;

while ((filePath = [enumerator nextObject]) != nil){

// If we have the right type of file, add it to the list
// Make sure to prepend the directory path
if([[filePath pathExtension] isEqualToString:type]){
[filePaths addObject:[directoryPath stringByAppendingPathComponent:filePath]];
}
}

[enumerator release];

return [filePaths autorelease];
}

Swift, using NSURL

func recursivePathsForResources(type type: String) -> [NSURL] {

// Enumerators are recursive
let enumerator = NSFileManager.defaultManager().enumeratorAtPath(bundlePath)
var filePaths = [NSURL]()

while let filePath = enumerator?.nextObject() as? String {

if NSURL(fileURLWithPath: filePath).pathExtension == type {
filePaths.append(bundleURL.URLByAppendingPathComponent(filePath))
}
}

return filePaths
}

When releasing an App update, can my data in the bundle path change or get deleted?

Files stored in the documents directory will not be removed during an app update. FFUserPrefs.plist is stored in the documents directory, so it will still be there after the update. Files stored in the app bundle ([NSBundle mainBundle]), however, will be replaced by the new bundle.

Xcode 6 / iOS 8 Simulator Data and Bundle folder script

This has been bugging me as well. I've not been able to solve it 100% but I created a quick and dirty app to help a bit. I can always find the device directory, but I've not yet found a way to track down the bundle / sandbox directories reliably. Source: https://github.com/somegeekintn/SimDirs

Edit: Went ahead and started scanning mobile_installation.log to find additional locations. Seems to find everything now.



Related Topics



Leave a reply



Submit