How to get exif information from ALAsset? - objective-c

I need to get exif information from selected asset and to display part of it on the screen.

[[asset defaultRepresentation] metadata];
returns a dictionary of dictionaries of metadata for the given asset representation. Check out this dictionary for the data you're interested in. I am not sure but I think the keys in that dictionary (and subdictionaries) are the same as the ones listed under CGImageProperties Reference.

This is a complete answer ... all in one spot
NSDictionary *nsd = [[asset3 defaultRepresentation] metadata];
NSString *widthStr = [nsd objectForKey: #"PixelWidth"];
NSString *heightStr = [nsd objectForKey: #"PixelHeight"];
NSLog(#"nsd: %# ... widthStr: %# ... heightStr: %# ...", nsd, widthStr, heightStr);
output:
nsd: {
ColorModel = RGB;
DPIHeight = 72;
DPIWidth = 72;
Depth = 8;
Orientation = 1;
PixelHeight = 1136;
PixelWidth = 642;
"{Exif}" = {
ColorSpace = 1;
ComponentsConfiguration = (
1,
2,
3,
0
);
ExifVersion = (
2,
2,
1
);
FlashPixVersion = (
1,
0
);
PixelXDimension = 642;
PixelYDimension = 1136;
SceneCaptureType = 0;
};
"{TIFF}" = {
Orientation = 1;
ResolutionUnit = 2;
XResolution = 72;
YResolution = 72;
};
} ... widthStr: 642 ... heightStr: 1136 ...

Related

How to extract NSString from NSDictionary that contains nested JSON

I'm trying to get NSStrings from an dictionary but the extracted strings contain the following
<__NSSingleObjectArrayI 0x28205fc00>(
Aaron
)
I expected s plain NSString.
Code:
NSString *name = [jsonDict valueForKeyPath:#"users.fName"];
NSLog(#"name, %#", name);
I though that using 'objectAtIndex' might work but it didn't.
Structure of NSDictionary (JSON) that I'm working with.
{
TYPE = UPDATE;
keys = (
{
calendarId = b306db7e1f924fdebade3813dd596f5d;
delFlag = 0;
editTime = "2019-10-23T12:02:32.0857328";
endTime = "2019-10-24T10:35:00";
insId = 20;
itemKeyId = 15;
keyId = ce71bc7ae3c145adad18a72e56cf0fab;
projectId = 950710ab2b96413cbfd186141e147b3e;
startTime = "2016-05-23T21:10:00";
updateStatus = 1;
validateCount = 6;
}
);
users = (
{
calendarId = 0;
delFlag = 0;
editTime = "2019-10-23T12:02:32.0794244";
fName = Aaron;
insId = 20;
itemUserId = 15;
keyId = ce71bc7ae3c145adad18a72e56cf0fab;
keyMac = 50338B11E912;
lName = Joines;
operId = 30222e0b4b0e4df6b669c3cf69245422;
projectId = 950710ab2b96413cbfd186141e147b3e;
userId = 8be21d1690bb46979a04b4e45a1ba625;
userPin = 123456;
}
);
}

Get the Array list based on the duplicate values in that Array Objective C

i have stuck up with below problem. I have got the below response.
(
{
CarrId = 102;
CarrName = "Fast and Furious";
CarrOptions = (
{
Id = 8;
Img = "400.jpg";
PImg = "412.jpg";
PQ = "S-30";
},
{
Id = 9;
Img = "400.jpg";
PImg = "412.jpg";
PQ = "M-30";
},
{
Id = 10;
Img = "603.jpg";
PImg = "611.jpg";
PQ = "S-30";
},
{
Id = 11;
Img = "603.jpg";
PImg = "611.jpg";
PQ = "M-30";
},
{
Id = 12;
Img = "603.jpg";
PImg = "611.jpg";
PQ = "L-30";
},
{
Id = 13;
Img = "738.jpg";
PImg = "749.jpg";
PQ = "S-30";
},
{
Id = 14;
Img = "738.jpg";
PImg = "749.jpg";
PQ = "M-30";
}
);
Status = 1;
}
)
Get the Array list based on the duplicate values in that Array Objective C. I need to get the array based on the PImg. For example if PImg = 412.jpg. i need the array something lik below
{
Id = 8;
Img = "400.jpg";
PImg = "412.jpg";
PQ = "S-30";
},
{
Id = 9;
Img = "400.jpg";
PImg = "412.jpg";
PQ = "M-30";
}
I have only done like getting the duplicates from the response
NSMutableDictionary * thisRow = [resultArray objectAtIndex:0];
NSMutableArray *pdctDtls = [thisRow objectForKey:#"CarrOptions"];
NSOrderedSet *orderedSet = [[NSOrderedSet orderedSetWithArray:pdctDtls] valueForKey:#"PImg"];
NSMutableArray *newarray = [orderedSet mutableCopy];
In newarray am getting the duplicate values. but if in the newarray if 412.jpg get the array related to 412.jpg. TIA
Try this. If you pass 611.jpg, you get 3 objects.
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"SELF CONTAINS[c] %#", #"611.jpg"]; // AS PER YOUR REQUIREMENT
NSArray *array =[pdctDtls filteredArrayUsingPredicate:predicate];
You could use an NSPredicate like so:
NSArray *pdctDtls = thisRow[#"CarrOptions"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"PImg = %#", #"412.jpg"];
NSArray *resultsWithSamePimg = [pdctDtls filteredArrayUsingPredicate:predicate];
if (resultsWithSamePimg.count > 1) {
// we have some duplicates
// ...
}
But I would rather use a plain old for loop, which might be easier to debug and understand.

How to efficiently loop through multiple nested NSDictionaries and compare values?

I have the following structure in an NSDictionary that I got after parsing the XMl using XMl reader from here http://troybrant.net/blog/2010/09/simple-xml-to-nsdictionary-converter/:
{
Document = {
Page = (
{
TextLR = {
Line = {
LineProps = {
applyBreakingRules = true;
autoDecimalTabPos = 0;
breakJust = BreakOptimal;
direction = ES;
hyphenationZone = 0;
kindAlign = Left;
kindJust = FullInterWord;
left = 0;
presSuppressWiggle = true;
rightBreak = 0;
rightJustify = 0;
text = "\n\t\n\t\t\n\t\t\t\n\t\t\t\t";
treatHyphenAsRegular = true;
};
Text = {
text = "\n\t\t\t\tHello ";
};
betweenBottom = false;
betweenTop = false;
bottomEnable = false;
break = EndPara;
cpLim = 12;
cpStart = 0;
direction = ES;
doc = Main;
firstLineCp = true;
};
bottom = 114115;
cpLim = 12;
cpStart = 0;
doc = Main;
left = 0;
right = 2438349;
text = "\n\t\t";
top = 0;
};
cpLim = 81963072;
fBuggyJust = false;
fEmptyPage = false;
fHasBubbles = false;
fSlicedPage = false;
height = 3448422;
marginBottom = 3448422;
},
{
TextLR = {
Line = {
LineProps = {
applyBreakingRules = true;
autoDecimalTabPos = 0;
breakJust = BreakOptimal;
direction = ES;
hyphenationZone = 0;
kindAlign = Left;
kindJust = FullInterWord;
left = 0;
presSuppressWiggle = true;
rightBreak = 0;
rightJustify = 0;
text = "\n\t\n\t\t\n\t\t\t\n\t\t\t\t";
treatHyphenAsRegular = true;
};
Text = {
text = "\n\t\t\t\tHello SO ";
};
betweenBottom = false;
betweenTop = false;
bottomEnable = false;
break = EndPara;
cpLim = 12;
cpStart = 0;
direction = ES;
doc = Main;
firstLineCp = true;
};
bottom = 114115;
cpLim = 12;
cpStart = 0;
doc = Main;
left = 0;
right = 2438349;
text = "\n\t\t";
top = 0;
};
cpLim = 81963072;
fBuggyJust = false;
fEmptyPage = false;
fHasBubbles = false;
fSlicedPage = false;
height = 3448422;
marginBottom = 3448422;
}
);
doc = "simple1.htm";
xdpi = 72;
xmlns = "http://apple/sites;
"xmlns:xsi" = "http://www.w3.org/2001/XMLSchema-instance";
"xsi:schemaLocation" = "xmlns = "http://apple/sites/Dump.xsd";
ydpi = 72;
};
}
I have been struggling to iterate through this nested NSDictionary and extract each attribute to compare with another NSDictionary of similar structure. The dictionaries can be somewhat dynamic, as in there might be additional levels of nesting for different xml files but the dictionaries to compare are of exact similar structure with same tags. Is there a way to iterate and create nested dictionaries on the go and then have parallel loops going so that I can extract the values and compare with between 2 NSDictionaries? I have tried the following code, but I am stuck in finding a good way to make it create dictionaries dynamically at the same time compare values/attributes with another dictionary. Help is much appreciated.
NSArray *arrPages = [[_xmlDictionary_master objectForKey:#"Document"] objectForKey:#"Page"];//this would return the array of Page dictionaries
for(int i=0;i<[arrPages count];i++){
NSDictionary *aPage = [arrStation objectAtIndex:i];
NSLog(#"id = %#",[aStation objectForKey:#"id"]);
}
Above code returns 2 Nested key/value pairs which in turn have multiple nested dictionaries. I am finding it hard to know which value has nesting and which doesnt during run time.
First tip: Refactor your data so that this isn't such a difficult operation! If that's not possible there's a few things you can try.
Rather than a "for loop", use:
[arrStation enumerateObjectsWithOptions: NSEnumerationConcurrent
usingBlock: ^(NSDictionary *aPage, NSUInteger idx, BOOL *stop) {
// Code here for compare
}];
That may perform your operations in parallel.
Another technique is using GCD. Using a dispatch_async, then a dispatch_apply can achieve something very similar.
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_apply([arrStation count], dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t idx) {
// Work here
});
});
Spend some time reading through the Concurrency Programming Guide. It's a great way to understand what options are available and how they work.

How to extract data values and added to tableview

How to extract the data from the below data structure, and display on tableview
id = extractData
[extractData objectForKey:#"data"] //BELOW IS OUTPUT:
( {
Name = {
id = 2;
name = rat;
};
Place = {
id = 7;
name = New York;
};
Item = {
Times = "100";
“expire” = 10-19-2015;
“value” = 300;
id = 1;
name = newname;
“checked” = 0;
};
Type = {
id = 1;
name = round;
};
},
{
Name = {
id = 2;
name = norway;
};
Place = {
id = 3;
name = ops;
};
Item = {
Times = "100";
“expire” = 10-18-2015;
“value” = 300;
id = 1;
name = new;
“checked” = 1;
};
Type = {
id = 2;
name = square;
};
}
)
Want to display Name,Place,Item,Type values in tableview cell with each iterations.
Can any one advice, how can extract value from above data.
Under your cellForRowAtIndexPath after initializing the custom cell add this code :
NSDictionary *dicVal = [yourDataArray objectAtIndex:indexPath.row];
cell.labelName.text = [[dicVal objectForKey:#"Name"] objectForKey:#"name"];
cell.labelPlace.text = [[dicVal objectForKey:#"Place"] objectForKey:#"name"];
cell.labelItem.text = [[dicVal objectForKey:#"Item"] objectForKey:#"name"];
cell.labelType.text = [[dicVal objectForKey:#"Type"] objectForKey:#"name"];
return yourCustomCell;
This should do the work. Thanks.

Accessing a Key in JSON Response

How in the following JSON response can I check if uids is nil ?
{
height = 480;
pid = "F#dd705e6b96a6e894556c0db84870501e_d97383cc80238c38b8907d99690fa1c9";
tags = (
{
attributes = {
glasses = {
confidence = 97;
value = false;
};
smiling = {
confidence = 97;
value = false;
};
};
center = {
x = "60.83";
y = "75.21";
};
gid = "<null>";
height = "49.58";
label = "";
manual = 0;
nose = {
x = "76.21";
y = "77.16";
};
pitch = "-5.55";
recognizable = 0;
roll = "-0.45";
uids = ( // <<<<<========== UIDs Key
);
width = "66.11";
yaw = "-19.56";
}
);
url = "http://face.com/images/ph/a6e529853432599dad6da996746cb070.jpg";
width = 360;
}
When I try :
if ([[[[photo objectForKey:#"tags"] objectAtIndex:0] valueForKey:#"uids"] count] == 0)
It keeps returning FALSE all the time.
I'm able to access a lot of these keys successfully. But it's just this one key that's giving me issues.
Like, to access the url key, I am using :
[photo objectForKey:#"url"];
And it's working absolutely fine.
What am I doing wrong with the uids key ?