views:

49

answers:

2

Hi,

I wanted to read version information of my application from the plit file.

For this I am using a code as shown below.

NSString *myFilePath = [[NSBundle mainBundle]
                                pathForResource:@"MyApp-Info"
                                ofType:@"plist"];

        // Format output

        NSLog(@"%@",myFilePath);

The output

 2010-08-31 17:14:10.095 MyApp[8759:20b] (null)

It always returns nil even if I tried to Import an existing file of type, text.txt still return nil, where text.txt is imported in the application.

I have goggled for the problem dont every one recommends to use NSBundel to read an pre imported file, but no use.

Any help, or an better way to read application version.

A: 

Got the solution via another link in the stack overflow here.

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];


        NSLog(@"%@",version);
Ameya
+1  A: 

The reason this doesn't work is because pathForResource looks for stuff inside "MyApp.app/Contents/Resources". The Info.plist file does not reside inside the resources folder, so it's going to return nil if you look for it there. The correct way to get at it is to use the "infoDictionary" method on NSBundle.

Dave DeLong
can u plz put the code here, so that it helps some one who is looking for some same kind of problem.
Ameya