【问题标题】:App crashes when i show alert view after successfully granting permissions from Twitter or facebook当我从 Twitter 或 facebook 成功授予权限后显示警报视图时应用程序崩溃
【发布时间】:2012-12-02 12:36:00
【问题描述】:

我正在为 iOS6 使用 Facebook 和 Twitter。 它运作良好。但是当我显示警报视图时,应用程序在 Twitter 和 Facebook 中都崩溃了。

以下是 Facebook 的代码。 如果我评论这条线[alert show]; 它运行良好。 不知道错在哪里。

-(IBAction)signInWithTweetPresses:(id)sender
{
    if([TWTweetComposeViewController canSendTweet])
    {

        self.view.userInteractionEnabled=NO;
        self.navigationController.navigationBar.userInteractionEnabled=NO;
        [self.spinner startAnimating];

        NSLog(@"signInWithTweetPresses called");
        ACAccountStore *store = [[ACAccountStore alloc] init];
        ACAccountType *twitterType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
        NSLog(@"store in aap delegate %@ ",store);
        NSLog(@"twittertype in aap delegate %@ ",twitterType);

        [store requestAccessToAccountsWithType:twitterType withCompletionHandler:^(BOOL granted, NSError *error) {
            if(granted) {
                // Remember that twitterType was instantiated above
                NSArray *twitterAccounts = [store accountsWithAccountType:twitterType];

                //////////////////
                if ([twitterAccounts count] > 0) {
                    // Grab the initial Twitter account to tweet from.
                    ACAccount *fbAccount = [twitterAccounts objectAtIndex:0];
                    NSLog(@"%@",fbAccount);
                    NSLog(@"accountsArray/loginWithFacebookClicked is    %@",twitterAccounts);

                    NSLog(@"username---%@\n accountDescription---%@ \n credential=====%@ \n fbAccount====%@",fbAccount.username,fbAccount.accountDescription, fbAccount.credential,fbAccount);

                    NSDictionary *tempDict = [[NSMutableDictionary alloc] initWithDictionary:[fbAccount dictionaryWithValuesForKeys:[NSArray arrayWithObject:@"properties"]]];
                    NSString *tempUserID = [[tempDict objectForKey:@"properties"] objectForKey:@"username"];
                    NSLog(@"tempUserID is  name is      %@",tempUserID);
                    self.emailStr=fbAccount.accountDescription;
                    self.nameForFacebook_String=fbAccount.username;
                    // self.fID_String=fbAccount.identifier;
                    self.fID_String = [NSString stringWithFormat:@"%@", [[fbAccount valueForKey:@"properties"] valueForKey:@"user_id"]] ;
                    NSLog(@"self.fID_String is  idd d is      %@",self.fID_String);
                    appDelegate.isForTwitterAlertBool=YES;
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@" " message:@"Successfully Logged in " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil , nil];
                    [alertView show];
                }
                NSLog(@"twitter cata in aap delegate %@ ",twitterAccounts);

            }
            else{
                [self.spinner stopAnimating];
                self.view.userInteractionEnabled=YES;
                self.navigationController.navigationBar.userInteractionEnabled=YES;
            }

        }];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Twitter Accounts" message:@"There are no Twitter accounts configured. You can add or create a Twitter account in Settings." delegate:nil                                                       cancelButtonTitle:@"OK"  otherButtonTitles:nil];
        [alert show];

    }

}

Facebook 代码:

-(IBAction)loginWithFacebookClicked:(id)sender
{
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
        self.view.userInteractionEnabled=NO;
        self.navigationController.navigationBar.userInteractionEnabled=NO;
        [self.spinner startAnimating];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sharingStatus) name:ACAccountStoreDidChangeNotification object:nil];

        NSLog(@"loginWithFacebookClicked narrrrrrrrrr");
        accountStore = [[ACAccountStore alloc] init];
        // Create an account type that ensures Twitter accounts are retrieved.
        ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
            NSArray * permissions = [NSArray arrayWithObjects:@"email",@"user_location", nil];
        NSDictionary * dict=[NSDictionary dictionaryWithObjectsAndKeys:@"111718528994116",ACFacebookAppIdKey,permissions,ACFacebookPermissionsKey,ACFacebookAudienceEveryone,ACFacebookAudienceKey, nil];

        [accountStore requestAccessToAccountsWithType:accountType options:dict completion:^(BOOL granted, NSError *error) {
            if(granted ) {
                NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

                // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
                if ([accountsArray count] > 0) {
                    // Grab the initial Twitter account to tweet from.
                    ACAccount *fbAccount = [accountsArray objectAtIndex:0];
                    NSLog(@"%@",fbAccount);
                    NSLog(@"accountsArray/loginWithFacebookClicked is    %@",accountsArray);

                    NSLog(@"username---%@\n accountDescription---%@ \n credential=====%@ \n fbAccount====%@",fbAccount.username,fbAccount.accountDescription, fbAccount.credential,fbAccount);

                    NSDictionary *tempDict = [[NSMutableDictionary alloc] initWithDictionary:[fbAccount dictionaryWithValuesForKeys:[NSArray arrayWithObject:@"properties"]]];
                    NSString *tempUserID = [[tempDict objectForKey:@"properties"] objectForKey:@"fullname"];
                    NSLog(@"tempUserID is  name is      %@",tempUserID);
                    self.emailStr=fbAccount.username;
                    self.nameForFacebook_String=tempUserID;
                    // self.fID_String=fbAccount.identifier;
                    self.fID_String = [NSString stringWithFormat:@"%@", [[fbAccount valueForKey:@"properties"] valueForKey:@"uid"]] ;
                    NSLog(@"self.fID_String is  idd d is      %@",self.fID_String);
                    appDelegate.isForFacebookAlertBool=YES;
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@" " message:@"Successfully Logged in " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil , nil];
                    [alertView show];
                }
            }
            else
            {
                [self.spinner stopAnimating];
                self.view.userInteractionEnabled=YES;
                self.navigationController.navigationBar.userInteractionEnabled=YES;
            }
        }];

    }
    else{

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Facebook Accounts" message:@"There are no Facebook accounts configured. You can add or create a Facebook account in Settings." delegate:nil                                                       cancelButtonTitle:@"OK"  otherButtonTitles:nil];
        [alert show];

    }
}

Facebook 的崩溃报告:CoreAnimation:警告,删除了未提交 CATransaction 的线程;在环境中设置 CA_DEBUG_TRANSACTIONS=1 以记录回溯。

【问题讨论】:

  • 当应用程序崩溃时,我首先要查找的是崩溃日志。使用崩溃日志更新您的问题
  • 编辑并将其添加到您的问题中,而不是作为评论。
  • 嘿,我正在添加,但它是说你的问题缺少正文 @0x8badf00d
  • 为进程纹身稍后制定崩溃报告 [9536] (UIKitApplication:com.johnhadenmac.tattoolater[0x643d][9536]) :作业似乎已崩溃:分段错误:08 年 12 月 11 日:01:30: 应用程序 'UIKitApplication:com.johnhadenmac.tattoolater[0x643d]' 异常退出信号 11: 分段错误: 12 月 14 日 08:01:30 Varmas-iPhone ReportCrash[9549] : libMobileGestalt copySystemVersionDictionaryValue: 可以不从系统版本字典中查找 ReleaseType Dec 14 08:01:31 Varmas-iPhone ReportCrash[9549] :

标签: iphone objective-c facebook twitter ios6


【解决方案1】:

使用以下代码显示警报,它应该可以工作:

dispatch_async(dispatch_get_main_queue(),^{

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@" " message:@"Successfully Logged in" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

[alertView show];

});

【讨论】:

    【解决方案2】:

    我认为您的警报视图代码导致崩溃,因为您在其他按钮标题中添加了 nil,请参阅此

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@" " message:@"Successfully Logged in " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil , nil];
    [alertView show];
    

    在 otherButtonTitles 你把 nil, nil

    这可能是导致崩溃的原因

    【讨论】:

    • 嘿,我试过你说的 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@" " message:@"Successfully Logged in " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] ;但仍然崩溃。 @Talha
    【解决方案3】:

    您的警报视图委托为零。试着做那个自己。

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@" " 消息:@“成功登录”委托:自我 cancelButtonTitle:@"OK" otherButtonTitles:nil , nil]; [警报视图 显示];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-18
      • 1970-01-01
      • 1970-01-01
      • 2017-02-25
      • 2013-07-10
      相关资源
      最近更新 更多