Saturday, March 5, 2011

Telling Openfeint that the challenge has been won/lost/tied

Are you having trouble telling the OpenFeint service when player B has won/lost/tied a challenge created by Player A?

Probably because the documentation is awful and there's little out there on OpenFeint challenges. It's relatively easy to get Player A to create challenges, but it's difficult to get Player B to get the challenge, its data, play it and then send back the result to the OpenFeint servers. One tip I have for you is to do with storing and using challenge data.

In your app's implementation of the challenge delegate sure that you have included #import "OFChallengeToUser.h" in the .h or .m of the delegate. Check out the main method of the delegate:

-(void) userLaunchedChallenge:(OFChallengeToUser*)challengeToLaunch withChallengeData:(NSData*)challengeData

Its first parameter is a OFChallengeToUser type. With OFChallengeUser.h included you can now call methods on challengeToLaunch:

NSString *challengeOriginatorUserID = [challengeToLaunch resourceId]


I could not call this method without the include. This data can now be stored and used where it is required by Player B to inform Openfeint that he has completed the challenge sent by Player A using the call:

[OFChallengeService submiteChallengeResult: challengeOriginatorUserID result:kChallengeResultRecipientWon resultDescription:@"I won" onSuccess:success onFailure:failure]


No comments:

Post a Comment

Share