iOS: OpenEers doesn't work - ios

I am trying to use OpenEars speech recognition kit, but doesn't work on my iPhone 3GS. I've written all code snippets provided by their tutorial, but nothing happens while speaking. Here's my code:
LanguageModelGenerator *lmGenerator = [[LanguageModelGenerator alloc] init];
NSArray *words = [NSArray arrayWithObjects:#"EAT", #"DRINK", #"SLOW", #"GO", nil];
NSString *name = #"NameIWantForMyLanguageModelFiles";
NSError *err = [lmGenerator generateLanguageModelFromArray:words withFilesNamed:name forAcousticModelAtPath:[AcousticModel pathToModel:#"AcousticModelEnglish"]]; // Change "AcousticModelEnglish" to "AcousticModelSpanish" to create a Spanish language model instead of an English one.
NSDictionary *languageGeneratorResults = nil;
NSString *lmPath = nil;
NSString *dicPath = nil;
if([err code] == noErr) {
languageGeneratorResults = [err userInfo];
lmPath = [languageGeneratorResults objectForKey:#"LMPath"];
dicPath = [languageGeneratorResults objectForKey:#"DictionaryPath"];
} else {
NSLog(#"Error: %#",[err localizedDescription]);
}
[self.openEarsEventsObserver setDelegate:self];
[self.pocketsphinxController startListeningWithLanguageModelAtPath:lmPath dictionaryAtPath:dicPath acousticModelAtPath:[AcousticModel pathToModel:#"AcousticModelEnglish"] languageModelIsJSGF:NO];

Related

How to retrieve specific value of key in json?

this is my json content.
[
{
"sha":"30eae8a47d0203ac81699d8fc2ab2632de2d0bba",
"commit":{
"author":{
"name":"Madhura Bhave",
"email":"mbhave#pivotal.io",
"date":"2017-03-23T23:14:32Z"
},
"committer":{
"name":"Madhura Bhave",
"email":"mbhave#pivotal.io",
"date":"2017-03-23T23:14:32Z"
},
"message":"Merge branch '1.5.x'",
}
}
]
and this is my main.i just want to retrieve key value from message and name,email,date from committer dictionary.i got stuck how to do that.
NSMutableArray *CommitArray = [[NSMutableArray alloc] init];
for (NSDictionary *CommitDictionary in CommitJson) {
CommitDict *commitDictObj = [[CommitDict alloc] init];
commitDictObj.message = [CommitDictionary objectForKey:#"message"];
for (NSDictionary *CommitterDictionary in [CommitDictionary objectForKey:#"committer"]) {
Committer *author = [[Committer alloc] init];
author.name = [CommitterDictionary objectForKey:#"name"];
author.email = [CommitterDictionary objectForKey:#"email"];
author.date = [CommitterDictionary objectForKey:#"date"];
}
[CommitArray addObject:commitDictObj];
}
for (int i =0 ; i < [CommitArray count] ; i++){
CommitDict *commitDictObj = [CommitArray objectAtIndex:i];
NSLog(#"Commit Message: %#", commitDictObj.message);
}
return 0;
}
}
i try fetch the json and display it value of message,name,email and date.how can i log the value of message, name, email and date?
Your array contains a dictionary, and that dictionary contains the commit dictionary, not the commit dictionary directly. Replace that part of your code:
for (NSDictionary *CommitDictionary in CommitJson) {
CommitDict *commitDictObj = [[CommitDict alloc] init];
With that:
for (NSDictionary *shaCommitDictionary in CommitJson) {
CommitDict *commitDictObj = [[CommitDict alloc] init];
NSDictionary *CommitDictionary = [shaCommitDictionary objectForKey:#"commit"];
(1) Convert JSON to NSDictionary
NSData *jsonData= ... // Assume you got the data already loaded
NSError *error = nil;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
(2) Access the dictionary values (fast enumeration available by now!!
NSString *message = dictionary[#"message"];
NSDictionary *author = dictionary[#"author"];
NSString *name = author[#"author"];
NSString *email = author[#"author"];
NSString *date = author[#"author"];
// OR:
// NSString *name = dictionary[#"author"][#"author"];
// NSString *email = dictionary[#"author"][#"author"];
// NSString *date = dictionary[#"author"][#"author"];
And thats it. I think the tricky thing is to get the JSON Data to the NSDictionary?
See here: https://stackoverflow.com/a/30561781/464016

How to get Mobile Number from vCard String Objective C

I am working on Action Extension Objective C. I have successfully created Extension for share recent contact in my Extension. In that I am getting v Card String. How can I get Mobile Number from v Card String. Any help would be appreciated.
Using contactsWithData:error: class method of CNContactVCardSerialization, you can retrieve info from a vCard.
It's from Contacts.framework, available since iOS9.
For earlier version, you can use AddressBook.framework. You can read info here.
NSError *errorVCF;
NSArray *allContacts = [CNContactVCardSerialization contactsWithData:[contactStr dataUsingEncoding:NSUTF8StringEncoding] error:&errorVCF];
if (!errorVCF)
{
NSMutableString *results = [[NSMutableString alloc] init];
//NSLog(#"AllContacts: %#", allContacts);
for (CNContact *aContact in allContacts)
{
NSArray *phonesNumbers = [aContact phoneNumbers];
for (CNLabeledValue *aValue in phonesNumbers)
{
CNPhoneNumber *phoneNumber = [aValue value];
[results appendFormat:#"%# %#\n", [aValue label], [phoneNumber stringValue]];
}
}
NSLog(#"Final: %#", results);
}

How do you get the "images" from a twitter feed to show in an iOS app

I have a code that accesses a Twitter feed and puts the text into a table. I then edited the code so I could display the text in my custom fashion in separate views, but I wanted to grab images from the tweets as well, and despite over an hour searching could not find a single reference. I have seen how to "Post" images, but to be clear, I need to get and "display" the images from the tweet in question.
Here are the highlights from my code that handles the Twitter Access:
-(void)twitterTimeLine
{
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted == YES)
{
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
ACAccount *twitterAccount = [arrayOfAccounts lastObject]; // last account on list of accounts
NSURL *requestAPI = [NSURL URLWithString:#"https://api.twitter.com/1.1/statuses/user_timeline.json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:#"30" forKey:#"count"];
[parameters setObject:#"1" forKey:#"incude_entities"];
SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters];
posts.account = twitterAccount;
[posts performRequestWithHandler:^(NSData *response, NSHTTPURLResponse *urlResponse, NSError *error) {
if (response)
{
// TODO: might want to check urlResponse.statusCode to stop early
NSError *jsonError; // use new instance here, you don't want to overwrite the error you got from the SLRequest
NSArray *array =[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&jsonError];
if (array) {
if ([array isKindOfClass:[NSArray class]]) {
self.array = array;
NSLog(#"resulted array: %#",self.array);
}
else {
// This should never happen
NSLog(#"Not an array! %# - %#", NSStringFromClass([array class]), array);
}
}
else {
// TODO: Handle error in release version, don't just dump out this information
NSLog(#"JSON Error %#", jsonError);
NSString *dataString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog(#"Received data: %#", dataString ? dataString : response); // print string representation if response is a string, or print the raw data object
}
}
else {
// TODO: show error information to user if request failed
NSLog(#"request failed %#", error);
}
self.array = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
if (self.array.count != 0)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData]; // this part loads into table - important!
});
}
}];
}
}
else
{
NSLog(#"%#", [error localizedDescription]);
}
}];
}
and here is how I display the Tweet
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = #"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
NSDictionary *tweet = _array[indexPath.row];
cell.textLabel.text = tweet[#"text"];
//NSString *element = [myArray objectAtIndex:2];
//NSString *element = myArray[2];
// I created some custom views to show the text, but kept the table for testing purposes
TemplateView *tempView = [viewArray objectAtIndex:testCounter];
tempView.TweetView.text = tweet[#"text"];
// -> this was what I was hoping for // tempView.ContentView.image = tweet[#"image"];
testCounter++;
if (testCounter >= 30)
{
testCounter = 0;
}
return cell;
}
I took out the key lines that I think is where I need to look:
tempView.TweetView.text = tweet[#"text"];
tempView.ContentView.image = tweet[#"image"];
// hoping that the latter would work as the first one does, but clearly it's not that simple
This might not be possible, if so, how would I get the images from the "link" (url) and make sure it is an image and not a video or other website?
I could set up a "word search" to grab text starting with http from the tweet and hopefully generate a URL from the string
TwitterKit doesn't seem to support images publicly.. I'm having the same stupid issue. The API internally holds images when using the built in tableview and datasource.. It requires a listID and a Slug.. However, when you want the images via JSON, you are out of luck! Even TWTRTweet object doesn't have entities or media properties!
Not sure how anyone can develop such an awful API.. In any case, I reversed the server calls made internally and found that it sends other "undocumented" parameters..
Example:
TWTRAPIClient *client = [[TWTRAPIClient alloc] init];
NSString *endpoint = #"https://api.twitter.com/1.1/statuses/user_timeline.json";
NSDictionary *params = #{#"screen_name":#"SCREEN_NAME_HERE",
#"count": #"30"};
will return NO MEDIA.. even if you have #"include_entities" : #"true".
Solution:
TWTRAPIClient *client = [[TWTRAPIClient alloc] init];
NSString *endpoint = #"https://api.twitter.com/1.1/statuses/user_timeline.json";
NSDictionary *params = #{#"screen_name":#"SCREEN_NAME_HERE",
#"count": #"30",
#"tweet_mode": #"extended"};
With tweet_mode set to extended (tweet_mode is an undocumented parameter), it will now return the media as part of the response.. This includes the "type" which is "photo" for images.
We can get tweets with images by applying "filter=images" query with "include_entities=true". It'll give tweets with media entities, under which we can see type="photo" and other related data.
For ex:
https://api.twitter.com/1.1/search/tweets.json?q=nature&include_entities=true&filter=images
Try this query at twitter developer console and see the response format: https://dev.twitter.com/rest/tools/console
Hope this will help.

empty json reponse in Foursquare2 venue Explore ios api

I'm working on iOS application with foursquare iOS api , I want to get the recommended near venues. I have used following code & it giving me an empty result .. Where have I done the mistake ? ? ?
NSArray* venues;
//get the foursquare locations
- (void)getTipsForLocation:(CLLocation *)location {
//NSLog(#"lat %f",location.coordinate.latitude);
[Foursquare2 venueExploreRecommendedNearByLatitude:#(location.coordinate.latitude)
longitude:#(location.coordinate.longitude)
near:nil
accuracyLL:nil
altitude:nil
accuracyAlt:nil
query:nil
limit:nil
offset:nil
radius:#(1500)
section:nil
novelty:nil
sortByDistance:1
openNow:0
venuePhotos:0
price:nil
callback:^(BOOL success, id result){
if (success) {
NSDictionary *dic = result;
venues = [dic valueForKeyPath:#"response.venues"];
FSConverter *converter = [[FSConverter alloc]init];
self.nearbyVenues = [converter convertToObjects:venues];
//NSLog(#"venues %#",venues);
//NSLog(#"near by places %#",self.nearbyVenues);
}
else{
NSLog(#" foursquare connecting error");
}
}];
NSLog(#"recommended place array %#",venues);
}
You Can Not pass Nil,In NSNumber & NSString.
NSNumber *emptynumber=[[NSNumber alloc] init];
[Foursquare2 venueExploreRecommendedNearByLatitude:lan longitude:lon near:#"" accuracyLL:emptynumber altitude:emptynumber accuracyAlt:emptynumber query:#"" limit:emptynumber offset:emptynumber radius:#(1500) section:#"" novelty:#"" sortByDistance:YES openNow:YES venuePhotos:YES price:#"" callback:^(BOOL success, id result) {
if (success) {
NSLog(#"secondResult: %#",result);
NSDictionary *dic = result;
NSArray *venues = [dic valueForKeyPath:#"response.venues"];
FSConverter *converter = [[FSConverter alloc] init];
self.venues = [converter convertToObjects:venues];
[self.tableView reloadData];
NSLog(#"Data: %#",venues);
}
}];
It Works For me.

Parsing Wordpress XML iOS / Objective-C

I am trying to create an iOS app which (besides a few other things) needs to load in the content of a Wordpress-Page
When I use the getPosts feature from Wordpress's XML-RPC feature, I get the following returned:
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<array><data>
<value><struct>
<member><name>post_id</name><value><string>23</string></value></member>
<member><name>post_title</name><value><string><!--:de-->Post1<!--:--><!--:en-->Post1<!--:--></string></value></member>
<member><name>post_date</name><value><dateTime.iso8601>20140211T14:26:39</dateTime.iso8601></value></member>
<member><name>post_date_gmt</name><value><dateTime.iso8601>20140211T12:26:39</dateTime.iso8601></value></member>
<member><name>post_modified</name><value><dateTime.iso8601>20140217T22:32:45</dateTime.iso8601></value></member>
<member><name>post_modified_gmt</name><value><dateTime.iso8601>20140217T20:32:45</dateTime.iso8601></value></member>
<member><name>post_status</name><value><string>publish</string></value></member>
<member><name>post_type</name><value><string>post</string></value></member>
<member><name>post_name</name><value><string>im-notfall</string></value></member>
<member><name>post_author</name><value><string>1</string></value></member>
<member><name>post_password</name><value><string></string></value></member>
<member><name>post_excerpt</name><value><string></string></value></member>
<member><name>post_content</name><value><string><!--:de--><b>Post1</b><!--:--><!--:en--><b>Post1</b><!--:--></string></value></member>
<member><name>post_parent</name><value><string>0</string></value></member>
<member><name>post_mime_type</name><value><string></string></value></member>
<member><name>link</name><value><string>http://example.com/ExampleProjekt/?p=23</string></value></member>
<member><name>guid</name><value><string>http://example.com/ExampleProjekt/?p=23</string></value></member>
<member><name>menu_order</name><value><int>5</int></value></member>
<member><name>comment_status</name><value><string>closed</string></value></member>
<member><name>ping_status</name><value><string>open</string></value></member>
<member><name>sticky</name><value><boolean>0</boolean></value></member>
<member><name>post_thumbnail</name><value><array><data>
</data></array></value></member>
<member><name>post_format</name><value><string>standard</string></value></member>
<member><name>terms</name><value><array><data>
<value><struct>
<member><name>term_id</name><value><string>1</string></value></member>
<member><name>name</name><value><string>Allgemein</string></value></member>
<member><name>slug</name><value><string>allgemein</string></value></member>
<member><name>term_group</name><value><string>0</string></value></member>
<member><name>term_taxonomy_id</name><value><string>1</string></value></member>
<member><name>taxonomy</name><value><string>category</string></value></member>
<member><name>description</name><value><string></string></value></member>
<member><name>parent</name><value><string>0</string></value></member>
<member><name>count</name><value><int>3</int></value></member>
</struct></value>
</data></array></value></member>
<member><name>custom_fields</name><value><array><data>
</data></array></value></member>
</struct></value>
<value><struct>
<member><name>post_id</name><value><string>9</string></value></member>
<member><name>post_title</name><value><string><!--:de-->Post2<!--:--><!--:en-->Post2<!--:--></string></value></member>
<member><name>post_date</name><value><dateTime.iso8601>20140206T13:16:56</dateTime.iso8601></value></member>
<member><name>post_date_gmt</name><value><dateTime.iso8601>20140206T11:16:56</dateTime.iso8601></value></member>
<member><name>post_modified</name><value><dateTime.iso8601>20140217T22:33:01</dateTime.iso8601></value></member>
<member><name>post_modified_gmt</name><value><dateTime.iso8601>20140217T20:33:01</dateTime.iso8601></value></member>
<member><name>post_status</name><value><string>publish</string></value></member>
<member><name>post_type</name><value><string>post</string></value></member>
<member><name>post_name</name><value><string>neuer-erster-beitrag</string></value></member>
<member><name>post_author</name><value><string>1</string></value></member>
<member><name>post_password</name><value><string></string></value></member>
<member><name>post_excerpt</name><value><string></string></value></member>
<member><name>post_content</name><value><string><!--:de--><b>Post2</b><!--:--><!--:en--><b>Post2</b><!--:--></string></value></member>
<member><name>post_parent</name><value><string>0</string></value></member>
<member><name>post_mime_type</name><value><string></string></value></member>
<member><name>link</name><value><string>http://example.com/ExampleProjekt/?p=9</string></value></member>
<member><name>guid</name><value><string>http://example.com/ExampleProjekt/?p=9</string></value></member>
<member><name>menu_order</name><value><int>3</int></value></member>
<member><name>comment_status</name><value><string>closed</string></value></member>
<member><name>ping_status</name><value><string>open</string></value></member>
<member><name>sticky</name><value><boolean>0</boolean></value></member>
<member><name>post_thumbnail</name><value><array><data>
</data></array></value></member>
<member><name>post_format</name><value><string>standard</string></value></member>
<member><name>terms</name><value><array><data>
<value><struct>
<member><name>term_id</name><value><string>1</string></value></member>
<member><name>name</name><value><string>Allgemein</string></value></member>
<member><name>slug</name><value><string>allgemein</string></value></member>
<member><name>term_group</name><value><string>0</string></value></member>
<member><name>term_taxonomy_id</name><value><string>1</string></value></member>
<member><name>taxonomy</name><value><string>category</string></value></member>
<member><name>description</name><value><string></string></value></member>
<member><name>parent</name><value><string>0</string></value></member>
<member><name>count</name><value><int>3</int></value></member>
</struct></value>
</data></array></value></member>
<member><name>custom_fields</name><value><array><data>
</data></array></value></member>
</struct></value>
<value><struct>
<member><name>post_id</name><value><string>5</string></value></member>
<member><name>post_title</name><value><string><!--:de-->Post3<!--:--><!--:en-->Post3<!--:--></string></value></member>
<member><name>post_date</name><value><dateTime.iso8601>20131217T17:32:09</dateTime.iso8601></value></member>
<member><name>post_date_gmt</name><value><dateTime.iso8601>20131217T15:32:09</dateTime.iso8601></value></member>
<member><name>post_modified</name><value><dateTime.iso8601>20140217T22:33:18</dateTime.iso8601></value></member>
<member><name>post_modified_gmt</name><value><dateTime.iso8601>20140217T20:33:18</dateTime.iso8601></value></member>
<member><name>post_status</name><value><string>publish</string></value></member>
<member><name>post_type</name><value><string>post</string></value></member>
<member><name>post_name</name><value><string>test-beitrag-2</string></value></member>
<member><name>post_author</name><value><string>1</string></value></member>
<member><name>post_password</name><value><string></string></value></member>
<member><name>post_excerpt</name><value><string></string></value></member>
<member><name>post_content</name><value><string><!--:de--><b>Post3</b><!--:--><!--:en--><b>Post3</b><!--:--></string></value></member>
<member><name>post_parent</name><value><string>0</string></value></member>
<member><name>post_mime_type</name><value><string></string></value></member>
<member><name>link</name><value><string>http://example.com/ExampleProjekt/?p=5</string></value></member>
<member><name>guid</name><value><string>http://example.com/ExampleProjekt/?p=5</string></value></member>
<member><name>menu_order</name><value><int>4</int></value></member>
<member><name>comment_status</name><value><string>closed</string></value></member>
<member><name>ping_status</name><value><string>open</string></value></member>
<member><name>sticky</name><value><boolean>0</boolean></value></member>
<member><name>post_thumbnail</name><value><array><data>
</data></array></value></member>
<member><name>post_format</name><value><string>standard</string></value></member>
<member><name>terms</name><value><array><data>
<value><struct>
<member><name>term_id</name><value><string>1</string></value></member>
<member><name>name</name><value><string>Allgemein</string></value></member>
<member><name>slug</name><value><string>allgemein</string></value></member>
<member><name>term_group</name><value><string>0</string></value></member>
<member><name>term_taxonomy_id</name><value><string>1</string></value></member>
<member><name>taxonomy</name><value><string>category</string></value></member>
<member><name>description</name><value><string></string></value></member>
<member><name>parent</name><value><string>0</string></value></member>
<member><name>count</name><value><int>3</int></value></member>
</struct></value>
</data></array></value></member>
<member><name>custom_fields</name><value><array><data>
</data></array></value></member>
</struct></value>
</data></array>
</value>
</param>
</params>
</methodResponse>
Specifically I would need the following fields:
post_id
post_title
post_motified
post_content
menu_order
I've tried a few options to achieve this.
One was using Gdata, which has been recommended in another post, but the example is for a simpler xml, and I can't seem to get it to work for me.
NSArray *tempPosts = [XMLdoc nodesForXPath:#"//methodResponse/params/param/value/array/data/value/struct/member" error:nil];
I also tried using the WPXMLRPC framework -> https://github.com/wordpress-mobile/wpxmlrpc
Using this code:
WPXMLRPCDecoder *decodedWPXML = [[WPXMLRPCDecoder alloc] initWithData:XMLcontent];
if ([decodedWPXML isFault]) {
NSLog(#"XML-RPC error %ld: %#", (long)[decodedWPXML faultCode], [decodedWPXML faultString]);
} else {
NSLog(#"XML-RPC response: %#", [decodedWPXML object]);
}
I manage to receive an object, which I can output via NSLog(#"%#", object);
But I fail to further process any data I receive that way.
I am (maybe obvious for some) very new to objective-c.
I have also looked at the official wordpress for iOS app, but I wasn't able to make use of any code.
Any help would be appreciated, I don't mind using any different frameworks/technologies, etc. if they help getting to my solution.
I am happy with Wordpress JSON plugin, it's free. You can easily fine tune your requests to specific pages and post types, it's well documented. What you get back from your site is always a structure of dictionaries and arrays in JSON (better then XML ;). Good way to examine the JSON structure is a JSON viewer.
Some sample code to get started.
- (void)loadNewsForPage:(NSUInteger)page
{
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.mywordpresssite.com/api/get_posts/?page=%lu", (unsigned long)page]]
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
// handle response
NSError *jsonError = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
if (!jsonError) {
if ([jsonObject isKindOfClass:[NSDictionary class]]) {
// fill datastore
[self newsIntoDataStore:(NSDictionary *)jsonObject forPage:page];
}
else {
NSLog(#"returned jsonObject is not a dictionary!");
}
} else {
NSLog(#"jsonError, news: %#", jsonError);
}
}] resume];
}
- (void)newsIntoDataStore:(NSDictionary *)news forPage:(NSUInteger)page
{
if ([[news objectForKey:#"status"] isEqualToString:#"ok"]) {
self.newsPages = [[news objectForKey:#"pages"] integerValue];
NSArray *posts = [news objectForKey:#"posts"];
if (posts.count > 0) {
// store individual posts
for (NSDictionary *post in posts) {
// determine post slug
NSArray *categoriesArray = [post objectForKey:#"categories"];
NSString *postSlug = nil;
NSString *desiredSlug = #"news";
if (categoriesArray.count > 0) {
for (NSDictionary *category in categoriesArray) {
if ([[category objectForKey:#"slug"] isEqualToString:desiredSlug]) {
postSlug = desiredSlug;
}
}
}
NSString *title = [post objectForKey:#"title"];
NSDate *dateFromAPI = [self.dateFormatterFromAPI dateFromString:[post objectForKey:#"date"]];
NSString *date = [self.dateFormatterForCell stringFromDate:dateFromAPI];
NSString *imageURLStringOrg = [[[post objectForKey:#"thumbnail_images"] objectForKey:#"full"] objectForKey:#"url"];
NSString *imageURLStringConverted = [imageURLStringOrg stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *attributedContentString = [[NSAttributedString alloc] initWithData:[[post objectForKey:#"excerpt"] dataUsingEncoding:NSUTF8StringEncoding] options:#{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];
NSString *content = [attributedContentString string];
NSString *url = [post objectForKey:#"url"];
if (title && date && imageURLStringConverted && content && url) {
NSDictionary *postDictionary = #{#"title" : title, #"date" : date, #"imageURL" : imageURLStringConverted, #"content" : content, #"url" : url};
[self.newsArray addObject:postDictionary];
} else {
NSLog(#"some post item empty, skipping this post: %lu", (unsigned long)[posts indexOfObject:post]);
}
}
}
dispatch_async(dispatch_get_main_queue(), ^{
if (self.pageLoaded < self.newsPages) {
[self loadNewsForPage:self.pageLoaded + 1];
} else {
[self.delegate newsFetchingCompleted];
}
});
} else {
NSLog(#"no objects in the array");
}
} else {
NSLog(#"returned status NOT OK");
}
}
GDataXMLDocument *XMLdoc = [[GDataXMLDocument alloc] initWithData:XMLcontent options:0 error:nil];
NSArray *XMLofPosts = [XMLdoc nodesForXPath:#"//methodResponse/params/param/value/array/data/value/struct/member" error:nil];
gives me an array of all post members that i can iterate via
for(GDataXMLElement *postMember in XMLofPosts){ ... }
Thansk for the help.
I've opened a new post for a more detailed question on the subject, since I found it's pretty much a different question, since it's on GDataXML more than getting the Wordpress XML
GDataXML nodesForXPath on Node contains items of entire GDataXMLDocument

Resources