-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];

    }

}

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を設定します。

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

あなたの Alert View デリゲートは nil です。そんな自分を作ってみてください。

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@" " message:@"ログインに成功しました " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil , nil]; [alertView ショー];

于 2012-12-14T15:37:30.397 に答える