2012-05-17 4 views
1

페이스 북에 연결하는 아이폰 애플리케이션을 만들고 있습니다. 첫 번째보기 컨트롤러 버튼을 클릭하여 연결하고 있습니다. 이제 두 번째 버튼을 추가하고 두 번째보기 컨트롤러를 엽니 다. 나는 알파벳 잤다 내 친구의 목록을 표시 그물을 검색 할하지만 난 내 응용 프로그램에서 적용 할 때, 내 위임 클래스에서 ME-아이폰 앱에 페이스 북 친구 목록 표시

도와주세요 런타임에 충돌

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 
    navController =[[UINavigationController alloc] initWithRootViewController:self.viewController]; 

    self.window.rootViewController = navController; 

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
     && [defaults objectForKey:@"FBExpirationDateKey"]) { 
     facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; 
     facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; 
    }    
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

-(void)fbDidLogin 
{ 
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];   
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];   
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];    
} 

로드 중 내 친구 목록을 표시하려는 두 번째보기 컨트롤러

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib.   
    NSArray *_permissions = [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", @"offline_access",@"read_friendlists",nil] retain];   
    [facebook authorize:_permissions];   
    facebook = [[Facebook alloc] initWithAppId:@"APP_ID_HERE" andDelegate:self];   
    [facebook requestWithGraphPath:@"me" andDelegate:self]; 
    [facebook requestWithGraphPath:@"me/friends" andDelegate:self]; 
    // NSMutableDictionary*params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"4",@"uids", @"name", @"fields", nil]; 
    [facebook requestWithGraphPath:@"me/friends" 
         andParams:[ NSDictionary dictionaryWithObjectsAndKeys:@"picture,id,name,link,gender,last_name,first_name",@"fields",nil] 
         andDelegate:self];   
} 

도움을 주시면 감사하겠습니다.

+0

여기서 충돌 로그를 언급하십시오. – iMash

+0

오류가 발생하면 스택 추적을 붙여 넣으십시오! –

+0

@ user1369291 나는 당신의 질문에 대한 답변을 upvoted 또는 accept하지 않았 음을 알았습니다. 친절하게 도움이되는 유용한 답변을 찾으면 그것을 upvote하십시오. 답변이 귀하의 질문에 대한 답변이라면, 동의하십시오. –

답변

0

이슈 # 1 :이 라인 : 당신이 시도하고 NSUserDefaults을 읽고 아직 초기화되지 않은 페이스 북 개체에 액세스하기 전에

facebook = [[Facebook alloc] initWithAppId:@"XXXXXXXXXXXXX" andDelegate:self]; 

요구 didFinishLaunchingWithOptions에서 앱 위임 될 수 있습니다. 또한보기 컨트롤러에서 제거해야합니다.

문제 # 2 : 앱 위임자와 뷰 컨트롤러에서 facebook 변수가 선언 된 것으로 보입니다. 전체 애플리케이션에는 Facebook 인스턴스가 하나만 있어야합니다. 또한 앱에서의 OpenURL 방법을 구현 있는지 확인해야합니다

Facebook *facebook = ((MyAppDelegate *)[[UIApplication sharedApplication] delegate]).facebook; 

: 당신이 당신의 뷰 컨트롤러에서 호출 할 때 당신은 당신의 애플 대리자에 저장된 페이스 북 인스턴스에 대한 참조를 얻기 위해 이런 일을해야 위임 한 후 설치 지침에 따라 plist 파일에 URL 체계를 만듭니다.

ps. AppId를 공개 포럼에 올리지 마십시오.

관련 문제