-1

我正在为 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];

    }

}

脸书的代码:

-(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 以记录回溯。

4

3 回答 3

1

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

dispatch_async(dispatch_get_main_queue(),^{

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

[alertView show];

});
于 2012-12-27T19:56:09.213 回答
0

我认为您的警报视图代码导致崩溃,因为您已将 nil 放在另一个按钮标题中,请参阅此

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

在 otherButtonTitles 你把 nil, nil

这可能是导致崩溃的原因

于 2012-12-14T13:57:42.253 回答
-1

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

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@" " message:@"成功登录" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil , nil]; [警报视图显示];

于 2012-12-14T15:37:30.397 回答