我正在尝试将iOS应用程序与Facebook集成。登录和大多数功能工作得很好,但我遇到了一个小问题,当我试图让FBWebDialogs分享用户发布的东西。它工作得很好,如果它是直接调用后张贴(调用函数),但当我尝试做同样的警报视图崩溃,它只是开始出现,突然消失之前完全没有破坏应用程序,没有错误抛出。它使用iOS 6的新Facebook功能,当用户登录iPhone设置时,它有原生视图而不是FBWebDialogs。我使用第三方库来自定义警报视图,但它与标准警报视图相同。
我认为这是与驳回视图的东西,但没有足够的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: ...
如果presentRequestsDialogModallyWithSession与performSelector(使用延迟)调用,那么崩溃问题似乎消失了-不知道为什么,但似乎在我的结束工作。
迟到了。但郑重声明…我已经修复了它使用:
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
代替:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
我相信这个问题与FBWebDialog被呈现而UIAlertView仍被显示有关。使用' did解散'确保警报已经消失,当webdialog出现