我想从我的iPhone应用程序向我的Facebook墙发送一些照片:
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];
}];
}];
}
代码完全有效,但正如您在代码中看到的那样,警报将显示_pageImages.count
时间。我可以轻松删除它。
我认为这可能是发布照片列表的更好方式。你能救我吗?
答案 0 :(得分: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];