Game Center localPlayer always authenticated - iphone

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

Related

XMPP authentication returns yes but XMPPStreamDidAuthenticate never called

I am trying to create an application that implements Facebook Chat. I have set up all of the XMPP stuff correctly to the best of my knowledge, but I cannot get it to work.
After the user has logged in and been authenticated to Facebook (via FBSession) I try to connect to the chat service. Here is where the XMPP comes in:
-(void)connect
{
[self setupStream];
NSError *err;
[self.xmppStream connectWithTimeout:10.00 error:&err];
}
-(void)setupStream
{
_xmppStream = [[XMPPStream alloc] initWithFacebookAppId:FACEBOOK_APP_ID];
[self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
- (void)xmppStreamDidConnect:(XMPPStream *)sender {
NSError *error;
NSError *err;
[self.xmppStream secureConnection:&err];
bool authed = [self.xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
NSLog(#"%#", err);
NSLog(#"%#", [self.xmppStream authenticationDate]);
NSLog(#"%d, %#", authed, error);
}
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender {
NSLog(#"did authenticate");
[self goOnline];
}
When running the above, everything seems to go fine: xmppStreamDidConnect is called after a short wait and authed always returns YES and its error is always null.
However, secureConnection returns Error Domain=XMPPStreamErrorDomain Code=1 "Please wait until the stream is connected." UserInfo=0xb23dc30 {NSLocalizedDescription=Please wait until the stream is connected.} The authenticationDate is always null as well. Also, none of the other delegate methods are ever called, including xmppStreamDidAuthenticate. What am I doing wrong?
I have finally found my answer!! Here it is, in case anyone else runs in to the same problem as me:
When calling openActiveSessionWithReadPermissions:allowLoginUI:completionHandler: the FBSession object does not actually communicate with the Facebook servers or attempt to authenticate with them, it simply loads the previous authenticationToken. In my case, this token had become invalid, but I did not realize it and nothing was there to tell me. I finally figured it out by logging the token and putting it in Facebook's Access Token Debugger. To check if your token is valid, you must call [FBSession renewSystemCredentials:] and await the result. Then you can determine if you need to manually closeAndClearTokenInformation before attempting to create a new token.

need XMPP Framework

I am working on ejabberd setup, i configured the server successfully, But in the client side we need XMPP Framework for this,
I Googled i got the following links
http://deusty.blogspot.in/2008/08/xmppframework-on-iphone.html
http://iphone4developer.blogspot.in/2011/07/how-to-add-xmpp-in-your-ios-project.html
I downloaded the robbiehanson / XMPPFramework but it throws errors, and some links gives me 404 error(they removed)
I downloaded the jabber client from this link (https://github.com/funkyboy/Building-a-Jabber-client-for-iOS) but the xmpp framework files throws errors(those are already deleted) from the app
I got one sample that is iPhoneXMPP sample but it throws error that is "Unable to connect to server. Check xmppStream.hostName" i given my host name in willSecureWithSettings method
Doubts:
1)Please Guide me to download the proper XMPP Framework with out errors
2)How to Configure ejabber client side?
Please guide me
Thanks a lot in advance
I downloaded the robbiehanson/XMPPFramework around 6 months back from this link: https://github.com/robbiehanson/XMPPFramework . I followed the steps that are mentioned in Getting Started section. It didn't throw any error. Just try to follow these steps to setup the xmppframework with your application.
In sample app, I found the function setupStream() that I am calling when I start my application. In this function I am creating an xmppStream and activating different modules that are needed in my application. e.g
xmppStream = [[XMPPStream alloc] init];
// Activate xmpp modules after creating them
[xmppReconnect activate:xmppStream];
[xmppRoster activate:xmppStream];
[xmppvCardTempModule activate:xmppStream];
[xmppvCardAvatarModule activate:xmppStream];
[xmppCapabilities activate:xmppStream];
// Add ourself as a delegate to anything we may be interested in
[xmppStream addDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
[xmppStream setHostName:XMPPHOST];
[xmppStream setHostPort:5222];
// You may need to alter these settings depending on the server you're connecting to
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
After setting the stream, you need to do authentication like this:
- (BOOL)connect:(NSString *)myJID //username registered with server
{
if (![xmppStream isDisconnected]) {
return YES;
}
if (myJID == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
NSError *error = nil;
if (![xmppStream connect:&error])
{
if(DEBUG)
{
NSLog(#"ERROR: Not connected to XMPP Server");
}
DDLogError(#"Error connecting: %#", error);
return NO;
}
return YES;
}
This function will be called by the framework and pass the password here:
- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
if(sender == xmppStream)
{
//DDLogVerbose(#"In xmppStream: %#: %#", THIS_FILE, THIS_METHOD);
isXmppConnected = YES;
NSError *error = nil;
if (![[self xmppStream] authenticateWithPassword:password error:&error])
{
DDLogError(#"Error authenticating: %#", error);
}
}
}
Now if user is authenticated, this function will be called:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
if(sender == xmppStream)
{
[self goOnline];
}
}
goOnline will send user's presence to server:
- (void)goOnline
{
XMPPPresence *presence = [XMPPPresence presence]; // type="available" is implicit
[xmppStream sendElement:presence];
}
Now you can send/receive the message/presence etc.
You will find a nice - complet - tutorial here: http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/

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.
}
}];
}

Server error when trying to report Achievement to GameCenter

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.

IPhone SDK: Audio Session Error: -12986 .... after upgrade to 3.1

I am building an iPhone audio app using Audio Sessions. Prototype was functioning till I decided to upgrade to 3.1
After a lot of hunting I finally found that the session activation call was failing with error code 12986.
I havent been able to find the reason for this anywhere.
The NSError object doesnt give any detail. I used the localized* APIs to get more info and this is what I got:
localizedDescription: Operation could not be completed. (OSStatus error -12986.)
localizedFailureReason: <blank>
localizedRecoverySuggestion: <blank>
Anyone know how to find more info about such error codes?
Meanwhile I will continue to dig and update this if my status changes.
My Code for the curious is -
NSError *myErr;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&myErr];
bSuccess= [audioSession setActive: YES error: &myErr];
Dont know what 12986 means exactly but it appears to be tied to the audio capabilities of the device now. And I have a solution!
I noticed that this error was popping up only when I use an iTouch and not on the IPhone. Since I was setting the session category as PlayAndRecord on both I decided to check if that was messing it up on the iTouch. Made the code a little smarter to detect if AudioInputIsAvailable and then set the Category accordingly (PlayBack on ITouch and PlayAndRecord on iPhone). That fixed it!
So it looks like this was being ignored in the prior SDKs. I had not changed anything earlier. :-)
Corrected Code Below:
NSError *myErr;
BOOL bSuccess = FALSE;
BOOL bAudioInputAvailable = FALSE;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
bAudioInputAvailable= [audioSession inputIsAvailable];
if( bAudioInputAvailable)
{
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&myErr];
}
else {
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&myErr];
}
bSuccess= [audioSession setActive: YES error: &myErr];
if(!bSuccess)
{
NSLog(#"Unable to Start Audio Session. Terminate Application.");
NSLog([myErr localizedDescription]);
NSLog([myErr localizedFailureReason]);
NSLog([myErr localizedRecoverySuggestion]);
}
I've had similar trouble trying to extract useful information from the error object as well when doing core data operations, i found the following code to be helpful in determining more precisely the cause of an error.
NSError *error;
... your code here ...
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0)
{
for(NSError* detailedError in detailedErrors)
{
NSLog(#" DetailedError: %#", [detailedError userInfo]);
}
}
else
{
NSLog(#" %#", [error userInfo]);
}
Sorry i couldn't help you out with your audio problem.
HTH