未调用fbDidLogin并且未调用handleURL

时间:2012-03-19 13:20:40

标签: iphone objective-c ios xcode facebook

我正在使用Facebook Connect与我的应用程序。一切都已建立,所有代码都在工作。在昨天,我可以使用我的应用程序登录,然后发布内容和其他功能。我不记得做出任何真正的改变。现在,像往常一样,每当我按下登录并进入Safari页面,我必须确认我要使用这个应用程序并且它说我登录的是谁。如果我按下确定它会回到应用程序。在整个过程中,在应用程序中,Facebook从不登录。记住:只是在这个工作中,我不记得做出任何改变!以下是连接的开始方式:

-(IBAction)connectToFacebook {

[loginButton setImage:[UIImage imageNamed:@"LoginWithFacebookPressed@2x.png"] 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;


}

所以我按一个按钮来调用这个IBAction。 NSTimer没有关系,只是为了一些按钮的外观。现在,这两个方法永远不会被调用(当我记录它时):

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

app id是最新的,我在ip plist中的url方案也是最新的。这有什么问题?

1 个答案:

答案 0 :(得分:0)

我猜你的应用程序没有获得登录facebook的任何access_token。它可能会给你null。

如果是问题。然后挂进FBDialog和

改变这个:

- (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;
}

用这个:

- (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;
}

它可能会解决您的问题。