0

I'm building an app with Appcelerator Titanium. It has an photo upload function so I've build an PHP backend (CodeIgniter + RESTful Server) to process the uploaded files. Since Titanium removes the EXIF data from the photos, I'm using the myMedia module to obtain the EXIF data so I can still post the EXIF data to the PHP backend.

The array which the module returns looks something like this:

{
exif =     {
    ApertureValue = "2.970853567123413";
    BrightnessValue = "5.906054496765137";
    ColorSpace = 1;
    ComponentsConfiguration =         (
        0,
        0,
        0,
        1
    );
    DateTimeDigitized = "2012:12:22 12:59:56";
    DateTimeOriginal = "2012:12:22 12:59:56";
    ExifVersion =         (
        2,
        2,
        1
    );
    ExposureMode = 0;
    ExposureProgram = 2;
    ExposureTime = "0.007936508394777775";
    FNumber = "2.799999952316284";
    Flash = 16;
    FlashPixVersion =         (
        1,
        0
    );
    FocalLenIn35mmFilm = 35;
    FocalLength = "3.849999904632568";
    ISOSpeedRatings =         (
        80
    );
    MeteringMode = 5;
    PixelXDimension = 2592;
    PixelYDimension = 1936;
    SceneCaptureType = 0;
    SensingMethod = 2;
    ShutterSpeedValue = "6.973695755004883";
    SubjectArea =         (
        1295,
        967,
        699,
        696
    );
    WhiteBalance = 0;
};
location =     {
    latitude = "52.51933333333334";
    longitude = "13.40083333333333";
};
path = "assets-library://asset/asset.JPG?id=E5040F0C-C86A-411B-ADA8-36C9EC91A526&ext=JPG";
}

I've done some research on the internet to find out what kind of array this is, and it seems a Plist (XML) to me. I've looked through the myMedia module Classes, and I've found out that it uses the NSDictionary Class to return the EXIF data.

I've tried some PHP Plist parses to process this array, but none of them actually work. I have no idea how to parse this array.

Thanks in advance!

pbdev
  • 1
  • 3
  • 5
    it's probably best to convert it in objective-c before sending it to PHP, you can convert NSDictonary to JSON (http://stackoverflow.com/questions/6368867/generate-json-string-from-nsdictionary) and then do a `json_decode()` in your API. – Prisoner Jan 11 '13 at 15:08
  • Yep, convert it to JSON on the Objective-C side. Among other things, the `description` format you have above is not "defined" and could change at Apple's whim. – Hot Licks Jan 11 '13 at 18:41

3 Answers3

0

take results from the module and convert it to a string. Pass the string to your server and convert it back to JSON... I am not a php guy, but I am guessing there is a way to parse JSON in php?

Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
0

This appears to be an old-style ASCII property list. You probably won't find any parsers for this format, as it's pretty much never used for interchange anymore — AFAIK only thing that can parse it is Apple's own libraries, and I'm not sure even they support this creaky old format. You probably got this from NSDictionary's description method, which is not intended for this purpose. To prepare the data for posting to the server, run it through NSJSONSerialization first and send that. Then you'll be dealing with ordinary JSON. (You could also run it through NSPropertyListSerialization and use the plist libraries you've found, but given both options, I can't see why you would choose that one.)

Chuck
  • 234,037
  • 30
  • 302
  • 389
  • Sure looks like a `description` dump of an NSDictionary to me -- easily converted to JSON. – Hot Licks Jan 11 '13 at 18:43
  • @HotLicks: Not as easy as just providing JSON in the first place. Yes, it is fairly easy to convert to JSON, but there are a number of corner cases you could forget to handle in your parser — and regardless of whether you end up caring about those, it will always be more work than just running your data through NSJSONSerialization on the client side. Deliberately sending `-[NSDictionary description]` is unreliable — it's not guaranteed to be in any particular format — and writing an ASCII-plist-to-JSON converter on the server side to deal with that bad decision instead of fixing it is nuts IMO – Chuck Jan 11 '13 at 20:40
  • That's what I said. Get the original JSON, or if it's in an NSDictionary, have it converted on the Objective-C side. In any event, the above is not a plist, it's an NSDictionary description. – Hot Licks Jan 11 '13 at 20:44
  • @HotLicks: Ah, I thought you were saying that converting the string to JSON was the easiest approach. My bad. As for whether it's a plist or "an NSDictionary description": AFAIK it's both. I'm pretty sure the description of an NSDictionary with only value objects is just an old-style plist of the dictionary. – Chuck Jan 11 '13 at 21:56
  • Rather vice-versa -- the "plist" you're familiar with is a NSDictionary description. The actual stored form of a plist is XML. – Hot Licks Jan 11 '13 at 22:42
  • @HotLicks: That's true these days, but the format in the OP — which is what NSDictionary's `description` gives — was the original plist format from NeXTStep. The XML format came later. In fact, NSDictionary still has support for reading the old format; it just doesn't write it anymore (aside from being its `description`). – Chuck Jan 11 '13 at 22:55
0

I've found a solution! JSONkit solved my problem. Apple's own JSON library didn't work, it was unable to convert the NSDictionary object to a JSON string.

I inserted this string in MyMediaModule.M (after line 1473):

NSString *JSONMeta = [metadata JSONString];

Then I replaced line 1475:

//[dictionary setObject:dictMeta forKey:@"metadata"];
[dictionary setObject:JSONMeta forKey:@"JSONMeta"];

Also don't forget to include the JSONkit library:

#import "JSONKit.h"

Now in Appcelerator Titanium just use event.JSONMeta instead of event.metadata:

mymedia.openPhotoGallery({
    success:function(event)
    {
        Ti.API.info(event.JSONMeta);
    }
}

Thank you for all your help! I had never coded in Objective-C so it was quite hard to start, but after all the solution is very simple.

pbdev
  • 1
  • 3