2012-03-19 5 views
0

J'utilise Facebook Connect avec mon application. Tout est mis en place, tout le code fonctionnait. Autour d'hier, je pourrais me connecter avec mon application, puis poster des trucs et d'autres fonctions. Je ne me souviens pas d'avoir fait de réels changements. Maintenant, comme d'habitude, chaque fois que j'appuie sur login et que je me rends sur une page Safari où je dois confirmer que je veux utiliser cette application et qu'elle indique qui je me connecte. Si j'appuie sur OK, cela revient à l'application. Pendant tout ce processus, dans l'application, Facebook ne se connecte jamais. N'OUBLIEZ PAS: JUSTE HIER Cela fonctionne, je ne rappelle pas faire des changements! Voici comment la connexion commence:fbDidLogin pas appelé et handleURL non appelé

-(IBAction)connectToFacebook { 

[loginButton setImage:[UIImage imageNamed:@"[email protected]"] forState:UIControlStateNormal]; 
facebook = [[Facebook alloc] initWithAppId:@"387500177929927" andDelegate:self]; 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { 
    facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; 
    facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; 
} 

if (![facebook isSessionValid]) { 
    [facebook authorize:nil]; 
}  
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(makeVisibleButtons) userInfo:nil repeats:NO]; 
[timer setAccessibilityHint:@"timer"]; 
} 

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // JUST SO THAT HANDLE URL CAN GET CALLED 

return YES; 


} 

Donc j'appuie sur un bouton pour appeler cette IBAction. Le NSTimer n'est pas lié, c'est juste pour l'apparition de certains boutons. Maintenant, ces deux méthodes ne sont jamais appelés (quand je LOGGUE):

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 
ConnectToFB *connect = [[ConnectToFB alloc] init]; 
return [connect.facebook handleOpenURL:url]; 
NSLog(@"url"); 
[connect release]; 
} 

- (void)fbDidLogin { 

NSLog(@"log in"); 

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; 
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; 
[defaults synchronize];  
} 

L'identifiant d'application est à jour et mes schémas d'URL dans les informations plist est à jour. Quel est le problème ici?

Répondre

0

Je suppose que votre application n'obtient pas access_token pour se connecter à Facebook. Cela pourrait vous rendre nul.

Si c'est le problem.Then en crochet dans FBDialog et

changer ceci:

- (NSString *) getStringFromUrl: (NSString*) url needle:(NSString *) needle { 
NSString * str = nil; 
NSRange start = [url rangeOfString:needle]; 
if (start.location != NSNotFound) { 
    // confirm that the parameter is not a partial name match 
    unichar c = '?'; 
    if (start.location != 0) { 
     c = [url characterAtIndex:start.location - 1]; 
    } 
    if (c == '?' || c == '&') {   
     NSRange end = [[url substringFromIndex:start.location+start.length] rangeOfString:@"&"]; 
     NSUInteger offset = start.location+start.length; 
     str = end.location == NSNotFound ? 
      [url substringFromIndex:offset] : 
      [url substringWithRange:NSMakeRange(offset, end.location)]; 
     str = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    } 
}  
return str; 
} 

avec ceci:

- (NSString *) getStringFromUrl: (NSString*) url needle:(NSString *) needle { 
NSString * str = nil; 
NSRange start = [url rangeOfString:needle]; 
if (start.location != NSNotFound) { 
    NSRange end = [[url substringFromIndex:start.location+start.length] rangeOfString:@"&"]; 
    NSUInteger offset = start.location+start.length; 
    str = end.location == NSNotFound 
    ? [url substringFromIndex:offset] 
    : [url substringWithRange:NSMakeRange(offset, end.location)]; 
    str = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
} 

return str; 
} 

Il peut résoudre votre problème.

+0

Je n'ai jamais implémenté cette méthode. Je l'ai ajouté mais il ne fonctionne toujours pas – MCKapur

+0

Avez-vous le jeton d'accès, alors que rappel de safari? – arindam

+0

Je ne suis pas sûr de ce que vous entendez par là, mon application ne directement à safari et lorsque l'utilisateur appuie sur OK dans Safari Facebook dialogue, il revient à l'application. Qu'entendez-vous par "avez-vous eu un jeton d'accès" @Sunny – MCKapur