views:

56

answers:

2

Hi all,

I have this simple method for returning the file path. I am passing the file name as argument. Then when I call this method this method returns 'null' if running on device but works fine on simulator. Is there anything I am doing wrong?

-(NSString*) getFilePathForFile:(NSString*)fileName
{
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [array objectAtIndex:0];
    NSString *temp = [documentsDirectory stringByAppendingPathComponent:fileName];
    return temp;
}

NSString *path = [self getFilePathForFile:@"settingInfo.plist"]

Any help would be appreciated. Thanks

A: 

It sounds like some sort of memory management problem. Have you tried to use "Build and Analyze" to see if Xcode can pick up any memory problems?

Otherwise, try this and see if you get something non-null:

NSString *path = [[self getFilePathForFile:@"settingInfo.plist"] retain];
William
A: 

The only way that method can fail and not throw an exception is if the array returned by NSSearchPathForDirectoriesInDomains is nil. Check that a valid array is being returned.

JeremyP