Server error when trying to report Achievement to GameCenter - iphone

When using the code from Apple,
- (void) reportAchievementIdentifier: (NSString*) identifier percentComplete: (float) percent
{
GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier] autorelease];
if (achievement)
{
achievement.percentComplete = percent;
[achievement reportAchievementWithCompletionHandler:^(NSError *error)
{
if (error != nil)
{
NSLog(#"problem with reporting");
NSLog(#"%#",[error localizedDescription]);
// Retain the achievement object and try again later (not shown).
}
}];
}
}
I get the error:
The requested operation could not be completed due to an error communicating with the server.
I have verified the user and it seems to register that i have played the game, but it cannot record the achievement. Any ideas?

Try using the reachability sample application from Apple to find out if the iPhone is connected to the internet via wifi or 3G. http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

It takes a few minutes for the Achievements from itunesconnect to propagate to the server.
Just try a little later, and it will not hurt to deinstall and install app again either.

Related

FBDialogs presentShareDialog does not work in both 5.1 and 6.1

id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:#"https://example.com/book/Snow-Crash.html"
forKey:#"book"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"books.reads"
previewPropertyName:#"book"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
I use the above codes to present a facebook shareDialog in my application ,but it does not work in both ios 5.1 and 6.1.I want to know the reason.
From my understanding as of now (I might be wrong), this code invokes the facebook native iOS app. If you are testing this on the simulator and don't have the iOS app installed, this will not work. It is unlikely you will be able to test this on the simulator. Try it on a real device that has the facebook iOS app installed.
Do you have the latest Facebook app installed?
Also, you're trying to post an open graph action using facebook's example action, which I'm not sure even exists. If you have registered custom open graph actions with you app, I suggest you modify your code to invoke it instead. If you don't have custom actions, I suggest starting with posting simple urls to see if it works for you.
Use:
NSURL* url = [NSURL URLWithString:#"https://developers.facebook.com/"];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
And lastly I suggest you read this: https://developers.facebook.com/ios/share-dialog/

VerificationController unrecognized selector iOS 5.0.1

I just added In-App Purchasing to my iOS app and a few of my users are crashing out with
-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0xf0a6f10
Obtained from BugSense, the memory location refers to the last line of this excerpt from Apple's VerificationController.m
- (BOOL)isTransactionAndItsReceiptValid:(SKPaymentTransaction *)transaction
{
if (!(transaction && transaction.transactionReceipt && [transaction.transactionReceipt length] > 0))
{
// Transaction is not valid.
return NO;
}
// Pull the purchase-info out of the transaction receipt, decode it, and save it for later so
// it can be cross checked with the verifyReceipt.
NSDictionary *receiptDict = [self dictionaryFromPlistData:transaction.transactionReceipt];
NSString *transactionPurchaseInfo = [receiptDict objectForKey:#"purchase-info"];
...
receiptDict is generated by this code (also included in VerificationController.m)
- (NSDictionary *)dictionaryFromPlistData:(NSData *)data
{
NSError *error;
NSDictionary *dictionaryParsed = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListImmutable
format:nil
error:&error];
if (!dictionaryParsed)
{
if (error)
{
#warning Handle the error here.
}
return nil;
}
return dictionaryParsed;
}
which should return an NSDictionary or nil.
ARC is turned on. This problem seems to only occur with iOS 5.0.1 users. While I did make necessary changes to VerificationController.m, this part has been untouched. I can't seem to replicate the problem on my iPad running iOS 5.1.1, but users have said that it is persistent even after reinstalling the app. If anyone can see something simple that I'm not doing right, I'd appreciate it.
EDIT
Follow up question. What does it mean when
- (BOOL)isTransactionAndItsReceiptValid:(SKPaymentTransaction *)transaction
transaction.transactionReceipt
only provides an NSString and is it safe to ignore?
looks like to me
propertyListWithData:data options:NSPropertyListImmutableformat:nil error:&error];
return a string not a dictionary but it doesnt seems logic. are you sure the problem come from this?

SKStoreViewController Sandbox issue

int productID = xxx;
NSDictionary *parameters = #{SKStoreProductParameterITunesItemIdentifier:[NSNumber numberWithInteger:productID]};
[self.storeViewController loadProductWithParameters:parameters
completionBlock:^(BOOL result, NSError *error) {
if (result)
{
[self presentViewController:self.storeViewController animated:YES completion:^{
}];
}
}];
I also created test account on itunes connect and earlier I was able to install this application through test account, but now each time or on other devices I got error. Screenshot attached
The alert view shows that your test was successful. Apple does not let you actually install it since it wants to avoid making app purchases in sandbox mode.

issue submitting score to a leaderboard

i have enabled Game Center in my itunes connect for my app.
In my game center, i have created a leaderboard named "Level 1" with its id "level1", integer.
In my game, i try to submit a score like this:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:#"level1"] autorelease];
int64_t score1 =scr;
scoreReporter.value = score1;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil) {
NSLog(#"Submit failed");
}
else {
NSLog(#"Score Submited");
}
}];
[pool release];
but i get a submit failed; i've created the leaderboard about 30-40 mins ago, could it not be enabled yet by apple? if else, i don't know what i'm doing wrong.
Here is my error:
Error: Error Domain=GKErrorDomain Code=6 "The requested operation
could not be completed because local player has not been
authenticated." UserInfo=0x1ed4d4a0 {NSLocalizedDescription=The
requested operation could not be completed because local player has
not been authenticated.}
btw i have internet access on my iphone and am connected on my phone to an apple account
Wasn't authentificated in game center, now it works!
Example from Game Center Programming Guide:
- (void) authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated)
{
// Player was successfully authenticated.
// Perform additional tasks for the authenticated player.
}
}];
}

Game Center localPlayer always authenticated

I'm trying to detect whether the local player authentication is working or not and it appears that I always get a positive result.
Here is the code I am using:
//--------------------------------------------------------------
- (void)authenticateLocalPlayer
{
NSLog(#"Authenticating local player %# (%d)", ([GKLocalPlayer localPlayer].authenticated? #"YES":#"NO"), [GKLocalPlayer localPlayer].authenticated);
if ([GKLocalPlayer localPlayer].authenticated == NO) {
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
[self callDelegateOnMainThread:#selector(authenticationChanged:)
withArg:nil
error:error];
}];
}
}
//--------------------------------------------------------------
- (void)authenticationChanged:(NSError *)error {
if (error != nil) {
NSLog(#"Error authenticating local player: %#", [error localizedDescription]);
}
NSLog(#"Authentication changed %# (%d)", ([GKLocalPlayer localPlayer].authenticated? #"YES":#"NO"), [GKLocalPlayer localPlayer].authenticated);
}
I tested this code while disconnected from the network and here is the trace output:
2010-12-13 13:20:59.799 LittleScreams[954:307] Authenticating local player NO (0)
2010-12-13 13:21:01.616 LittleScreams[954:307] Error authenticating local player: The Internet connection appears to be offline.
2010-12-13 13:21:01.621 LittleScreams[954:307] Authentication changed YES (1)
It clearly sees that the connection is offline but is still authenticating the player! Any ideas what's going on? I'm getting the same result on the device and in the simulator.
TIA
I think you shouldn't call authenticationChanged manually, take a look at Game Kit Programming Guide and follow the steps, that worked for me.
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Users/Users.html