views:

524

answers:

1

I am trying to count total photos on the iphone and get the total filesize. What is the best way?

+1  A: 

At least in 2.x SDKs, you can't access actual photo files programmatically from code. However, you can access thumbnails of photos which you can use to get a count of photos.

Original photo themselves are in a special database file (/private/var/mobile/Media/Photos/Photo Database) and thumbnail pictures are in a directory (/private/var/mobile/Media/Photos/Thumbs).

Photos can be accessed only through interactive UIImagePickerController. Reverse engineering Photo Database file format is the only way I can see that would give you an access to original photo files programmatically.

I haven't checked the situation for 3.0 SDK, it might give you some API to access photos programmatically.

tequilatango
I dont think they will ever let you access photos fromthe photo album programatically without user concent, that would allow programs to potentially grab pictures without users consent and use them places
Daniel
Agreed. Either it's through interactive controls (like now) or then they implement permission control in a similar way that location data currently has, i.e. user grants a permission for a certain app to access photos without a user concent per photo.
tequilatango
Not sure if this will be allowed but works for nowNSString *MyPath = @"/private/var/mobile/Media/DCIM/100APPLE/"; NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath:MyPath]; NSLog(@"Total Files: %d", [directoryContent count]-1); NSLog(@"%@", directoryContent);
ppm7