2012-10-29 60 views
0

到時間線我想從我的iPhone應用程序發送一些照片給我的Facebook牆上:郵相冊使用Facebook的iOS版SDK

for (int i=0; i<_pageImages.count; i++) { 
    UIImage *img = [self.pageImages objectAtIndex:i]; 
    NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; 
    [params setObject:@"my custom message" forKey:@"message"]; 
    [params setObject:img forKey:@"picture"]; 

    [self performPublishAction:^{ 
     [FBRequestConnection startWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST" 
      completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
       [self showAlert:@"Photo med text Post" result:result error:error]; 
     }]; 
    }]; 
} 

的代碼,你在代碼中看到Alert'll完全有效,但顯示_pageImages.count時間。我可以很容易地刪除它。

我認爲這可能是更好的方式發佈照片列表。你可以幫幫我嗎?

回答

0

如果你的意圖是隻顯示警告一次,你可以初始化你上傳的圖像的全局計數,而不是調用showAlert:result:error方法,你可以調用一個新的方法。新方法將處理結果並增加處理圖像的本地計數。當本地計數達到全球計數時,您可以顯示警報。

你也可以想想配料您的要求,請參閱https://developers.facebook.com/docs/howtos/batch-requests-ios-sdk/

你可以循環邏輯可能更改爲:

// Before the loop 
FBRequestConnection *connection = [[FBRequestConnection alloc] init]; 

// Loop through images, set up the request 
for (int i=0; i<_pageImages.count; i++) { 
    .... 
    FBRequest *request = [FBRequest requestWithGraphPath:@"me/photos" 
        parameters:params 
        HTTPMethod:@"POST"]; 
    [connection addRequest:request 
     completionHandler: 
      ^(FBRequestConnection *connection, id result, NSError *error) { 
       // Call your method to check results and keep count 
       // of the callbacks before displaying the final output 
    }]; 
} 

// After the loop 
[connection start]; 
+0

我很欣賞你的幫助。很快我會檢查它並回復。 – Ali

相關問題