Having two Facebook request paths in same controller iOS SDK - iphone

I am having a controller where I need issue multiple facebook requests. How do I tell the request appart in this delegate method?
- (void)request:(FBRequest *)request didLoad:(id)result { ... }
I need to do one thing for one request and another thing for the other request.

How about write individual class request & results from delegates , i used to try this when in Single View i need to take Friends List, Checkins Data , User Info.
i ll create three separate delegate results & get results back .
However making multiple requests will work but it will create bad performances when any one of the requests failed or goes wrong.
Hope it helps
Updated :
userInfo *uInfo = [UserInfo alloc]init];
[uinfo getuserDetails];
[uInfo release];
create a protocol to return results of user info back to view class like
In UsuerInfo class
-(void)request:(FBRequest *)request didLoad:(id)result {
[delegate finfinishedGettingUserInfoDetails:result] // convert to array
}
IN your view class get back the results as
-(void)finishedGettingUserInfoDetails : (NSMutableArray *)userArr {
yourInstanceArray = [userArr copy];
}
do this for all multiple requests.

Related

How to send custom string with QBRTCSession object

In my application I have implemented quickblox SDK for voice and video call and everything is working perfectly. There is just one issue which I am facing. To track the particular call in background I have a session created between two users. But while making this call I want to send the same session Id to the opponent also. If somebody could help me please tell me how could i do this.
Thanks in advance
Got the solution!!
Refer http://quickblox.com/developers/Sample-webrtc-ios
Before making a call I have following line of code written in my file
[self.session startCall:userInfo];
Here you can write anything inside userInfo dictionary. As soon as opponent receives the call
- (void)didReceiveNewSession:(QBRTCSession *)session userInfo:(NSDictionary *)userInfo
will be called. Here whatever you have written inside userInfo, you can read it directly.
[QBRTCClient.instance addDelegate:self];
// 2123, 2123, 3122 - opponent's
NSArray *opponentsIDs = #[#3245, #2123, #3122];
QBRTCSession *newSession = [QBRTCClient.instance createNewSessionWithOpponents:opponentsIDs
withConferenceType:QBConferenceTypeVideo];
// userInfo - the custom user information dictionary for the call. May be nil.
NSDictionary *userInfo = #{ #"key" : #"value" };
[newSession startCall:userInfo];
Start call method definition says the same
/**
* Start call. Opponent will receive new session signal in QBRTCClientDelegate method 'didReceiveNewSession:userInfo:
*
* #param userInfo The user information dictionary for the stat call. May be nil.
*/
- (void)startCall:(NSDictionary *)userInfo;

List of chat room members

How can I retrieve the list of members of a chat room in using XMPP framework?
I tried using:
- (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items
But it returns an empty array
This question is old but I recently encountered this exact issue (xmppRoom:didFetchMembersList: is passed an empty array). In my case the problem was that when users got invited to the room they would have a role of "participant" and an affiliation of "none". The fetchMembersList method in XMPPRoom looks for items with an affiliation of "member".
You can change the affiliation like so:
[xmppRoom editRoomPrivileges:#[[XMPPRoom itemWithAffiliation:#"member" jid:userJID]]];
For details on roles and affiliations, see XEP-0045.
use this method when you invite users.
-[xmppRoom editRoomPrivileges:#[[XMPPRoom itemWithAffiliation:#"member" jid:userJID]]];
After you create xmpproom object and call following delegate method
-(void)xmppRoomDidJoin:(XMPPRoom *)sender{
[sender fetchMembersList];
}
- (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items{
NSLog(#"print user list=====%#",items);
for (NSXMLElement *xmlItem in items) {
NSString *jid = [[xmlItem attributeForName:#"jid"]stringValue];
NSLog(#"print user jid=====%#",jid);
}
}

Accessing GTLPlusActivity properties

I have integrated the Google Plus iOS SDK v1.2.1 into my iOS app. After authentication I am trying to fetch the user's activity feed. My code is the following:
GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
plusService.retryEnabled = YES;
GTLQueryPlus *query = [GTLQueryPlus queryForActivitiesListWithUserId:#"me" collection:kGTLPlusCollectionPublic];
[plusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusActivityFeed *data,
NSError *error) {
for (GTLPlusActivity *activity in data.items) {
// ITERATE THROUGH THE ACTIVITIES
NSString *publishedDate = activity.published; <---- ERROR
// "PROPERTY 'published' CANNOT BE FOUND
// IN FORWARD CLASS OBJECT "GTLPLusActivity""
// WHY ARE THE VARIABLES SUCH AS published, placeName,
// title, actor etc NOT ACCESSIBLE
}
}];
I am able to successfully retrieve the posts of the user. The GTLPlusActivity class has many properties as shown in the image:
Whenever I try to access the properties using the "." operator such as "activity.actor" in the for loop, it gives the error "Property 'actor' cannot be found in forward class object 'GTLPlusActivity'". Why am I unable to access the properties? I need to display them in a UITableView.
EDIT: Code Snapshot. Error clearly displayed in Red.
Firstly, check the error condition and make sure the error code is nil. I have tried your code, and it works correctly on my end, so most likely, there is a problem with the response you are getting back. Generally activity.actor will return a GTLPlusActivityActor.
Try something like:
if (error) {
NSLog(#"Status: Error: %#", error);
}
else
<Do stuff>
EDIT: Also, our iOS quick-start is a great resource for seeing how we handle certain parts of the code. The ListMoments bit is pretty similar to dealing with Activities.
https://developers.google.com/+/quickstart/ios
EDIT 2: Also, make sure you have all of the right imports. Try
#import "GTLPlusActivity.h"
or
#import "GTLPlus.h"

What is the most efficient way to sync Core Data with JSON API

What would be the best way to sync my Core Data schema with a remote API serving JSON? At the moment I'm looping through each dictionary in the JSON response checking Core Data to see if the API ID exists.
This works great, but all thats left to do now is delete any local objects that aren't on the server. Here is an example of my JSON data:
[
{
"id":1234,
"name":"My first object",
"description":"This is a long string with lots of information"
},
{
"id":1235,
"name":"My second object",
"description":"This is a long string with lots of information"
}
]
Currently the only way I can think of accomplishing this is something like the following:
NSArray *jsonData = // Convert json data to array using NSJSONSerialization
NSInteger fetchedCount = _fetchedResultsController.fetchedObjects.count;
if (fetchedCount != jsonData.count) {
for (int i = 0; i < fetchedCount; i++) {
NSManagedObject *object = [_fetchedResultsController objectAtIndexPath: [NSIndexPath indexPathForItem:i
inSection:0]];
NSNumber *idNumber = object.apiID;
BOOL shouldDelete = YES;
for (NSDictionary *jsonDict in jsonData) {
if ([jsonDict objectForKey:#"id"] == idNumber) {
shouldDelete = NO;
}
}
if (shouldDelete) {
// Delete object.
}
}
}
I think that will be massively inefficient if the JSON array contains a lot of objects.
This could be ok, but I think you should apply the Find-or-Create pattern suggested in Apple doc. See here for a deep explanation Efficiently Importing Data (In particular see Implementing Find-or-Create Efficiently).
The overall idea is quite simple. Having two arrays of objects (the one you retrieve from Core Data and the one you retrieve from the service) that are ordered (by apiID and id resp.).
Obviously if there are a lot of data, I really suggest to perform operations in background. Remember that each thread needs to rely on its NSManagedObjectContext. Otherwise take advantage of new queue mechanism provided by iOS 5 API.
For the sake of completeness, I also suggest to read RayWenderlich tutorial How To Synchronize Core Data with a Web Service Part 1 and 2. It's very interesting.
Hope that helps.

How to use Three20 framework to upload multiple images and handle JSON response?

So I have an iPhone application that needs to:
Post several strings and up to 5 images (stored in memory) to a RoR web application
Parse the JSON returned that will include several strings and an array of URLs (each representing the location of where the uploaded images can be found on the website).
QUESTIONS:
Can this be done with Three20 (would be nice since I'm using it for other things)? And if so, how?
If it can't be done with Three20 ... how would it be accomplished using ASIHttpRequest? Or maybe something baked into the SDK if that is a better option?
Thanks much
Unfortunately there isn't a whole lot of tutorials and good documentation for three20 out there on the web ... so here is how I finally got things working:
- (void) sendToWebsite {
NSString* url = [[NSString stringWithFormat:kRequestURLPath, self.entityId] stringByAppendingString:#".json"] ;
// Prep. the request
TTURLRequest* request = [TTURLRequest requestWithURL: url delegate: self];
request.httpMethod = #"POST";
request.cachePolicy = TTURLRequestCachePolicyNoCache;
// Response will be JSON ... BUT WHY DO I NEED TO DO THIS HERE???
request.response = [[[TTURLJSONResponse alloc] init] autorelease];
// Set a header value
[request setValue:[[UIDevice currentDevice] uniqueIdentifier] forHTTPHeaderField:#"Device-UID"];
// Post a string
[request.parameters setObject:self.entity_title forKey:#"entity_title"];
// Post some images
for (int i = 0; i < [self.photos count]; i++) {
// IS IT POSSIBLE TO ADD A PARAM NAME SO I CAN LOOK FOR THE SAME NAME
// IN THE WEB APPLICATION REGARDLESS OF FILENAME???
[request addFile:UIImagePNGRepresentation([self.winnerImages objectAtIndex:i])
mimeType:#"image/png"
fileName:[NSString stringWithFormat:#"photo_%i.png", i]];
}
// You rails guys will know what this is for
[request.parameters setObject:#"put" forKey:#"_method"];
// Send the request
[request sendSynchronously];
}
Things I still don't understand (or find problematic):
For a posted file, how can I include both a param name AND a filename?
What is the purpose of setting request.response = to whatever? I don't get that.
Answering #2:
You need to supply the handler for the response before you send your request, the TTURLJSONResponse is not the actual response, but it's responsible for handling the response. This is where you'd process the response for your strings and array of URLs.
It's really a protocol called TTURLResponse that defines the following method for implementation:
/**
* Processes the data from a successful request and determines if it is valid.
*
* If the data is not valid, return an error. The data will not be cached if there is an error.
*
* #param request The request this response is bound to.
* #param response The response object, useful for getting the status code.
* #param data The data received from the TTURLRequest.
* #return NSError if there was an error parsing the data. nil otherwise.
*
* #required
*/
- (NSError*)request:(TTURLRequest*)request
processResponse:(NSHTTPURLResponse*)response
data:(id)data;
You chose TTURLJSONResponse as your handler, which is a straight-forward implementation to look at for help on writing your own.