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