我正在尝试将 iOS 应用程序与 Facebook 集成。登录和大多数功能运行良好,但当我尝试让 FBWebDialogs 共享用户发布的内容时,我遇到了一个小问题。如果在发布(调用函数)后直接调用它,它效果很好,但当我尝试从警报 View 执行相同操作时,它会崩溃,它刚刚开始出现,然后在完全加载之前突然消失,而不会破坏应用程序,并且不会引发任何错误。当用户在 iPhone 设置中登录时,它使用 iOS 6 中的新 Facebook 功能来工作,该功能具有 native View 而不是 FBWebDialogs。 我使用第三方库来自定义警报 View ,但它与标准警报 View 的作用相同。
我认为这是一种不屑一顾的观点,但对 iOS 的了解还不够,无法确定。任何想法?。谢谢。
这就是代码:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex)
{
case 1:
{
[self sharePostOnFacebook];
break;
}
default:
break;
}
}
调用了下一个方法,但模态视图永远不会完全显示。它只是闪烁然后消失
-(void) sharePostOnFacebook
{
if (shareData !=nil && [[shareData objectForKey:@"success"] boolValue])
{
NSString *caption = [shareData objectForKey:@"caption"];
. ..........
BOOL displayedNativeDialog =
[FBNativeDialogs
presentShareDialogModallyFrom:self
initialText:description
image:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:picture]]]
url:[NSURL URLWithString:link]
handler:^(FBNativeDialogResult result, NSError *error) {
.........
}];
// Fallback, show the view controller that will post using me/feed
if (!displayedNativeDialog)
{
[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];
// Put together the dialog parameters
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
.............
nil];
FBSession *activeSession = [FBSession activeSession];
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:activeSession
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
........
}];
}
}
}
最佳答案
这是我解决的解决方案 ( https://developers.facebook.com/docs/howtos/send-requests-using-ios-sdk/ )。
关键似乎是延迟对 FBWebDialog 的调用。
[self performSelector:@selector(sendRequest) withObject:nil afterDelay:0.5];
sendRequest 可以是
- (void)sendFlyerFloRequestToFriends
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[FBWebDialogs presentRequestsDialogModallyWithSession: ...
如果使用performSelector(使用延迟)调用presentRequestsDialogModallyWithSession,那么崩溃问题似乎消失了 - 不知道为什么,但似乎对我有效。
关于ios - 单击“警报 View ”按钮后 Facebook Web 对话框崩溃 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15790422/