簡體   English   中英

從設置中刪除Twitter帳戶會使用iOS5 twitter框架崩潰應用程序

[英]Deleting Twitter Account from settings crashes the application using iOS5 twitter framework

我使用iOS 5 Twitter框架並保存了ACAccount對象。 如果用戶從設置中刪除特定帳戶,則應用程序(顯然)會崩潰。 我當前的解決方法只保存用戶名並重新獲取Twitter帳戶數組並匹配用戶名以獲取正確的帳戶。 有沒有更好的工作? 我知道ACAccountStore有通知

ACAccountStoreDidChangeNotification

但我沒有收到它。

下面的代碼是固定版本。 在這里,我將比較之前的帳戶用戶名。 如果我刪除它並使用之前用戶選擇的AccountObject,並且如果用戶更改了該帳戶,則應用程序將崩潰。

if([TWTweetComposeViewController canSendTweet]){

        ACAccountStore *store = [[ACAccountStore alloc] init];
        ACAccountType *twitterType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
        [store requestAccessToAccountsWithType:twitterType withCompletionHandler:^(BOOL granted, NSError *error) 
         {

             if(granted)
             {
                NSArray *arrayOfAccounts =  [store accountsWithAccountType:twitterType];
                 if (arrayOfAccounts != nil && [arrayOfAccounts count]>0) {
                     for(ACAccount *anAccount in arrayOfAccounts)
                     {
                         if ([anAccount.username isEqualToString:previousAccount.username] ) {
                             [self setPhoneTwitterAccount:anAccount]; //alwAYS SET the new Account.
                             break;
                         }
                     }
                     //previous account was deleted if a userName match was not found
                     //show the picker or just pick the first account.
                     //TODO: provide a picker from here as well.
                     if (self.phoneTwitterAccount == nil) {
                         self.phoneTwitterAccount = [arrayOfAccounts objectAtIndex:0];
                     }

                 }
             }
         }];
    }

使用舊帳戶時會發生崩潰:

 TWRequest* twitterRequest_5 = [[[TWRequest alloc] initWithURL:profileURL 
                                                          parameters:parameters
                                                       requestMethod:TWRequestMethodGET]autorelease];

        [twitterRequest_5 setAccount:phoneTwitterAccount];    

        [twitterRequest_5 performRequestWithHandler:^(NSData *responseData,NSHTTPURLResponse *urlResponse, NSError *error);

我有一個與ACAccounts類似的問題,我的應用程序會崩潰,每次執行以下塊時調試器都會給我一個EXC_BAD_ACCESS:

performRequestWithHandler:^(NSData *responseData,NSHTTPURLResponse *urlResponse, NSError *error) 

當我在應用程序委托中將ACAccountStore保留為實例變量時,問題得以解決。 也許您可以嘗試在應用程序委托中分配和初始化ACAccountStore一次,然后在每次需要從中獲取帳戶數據時引用該實例,而不是在需要獲取Twitter帳戶數據時分配和初始化新實例。

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
ACAccountStore *store = appDelegate._accountStore;

目前還不是很清楚ACAccountStore和ACAccount之間的關系是什么,但文檔說“每個ACAccount對象都屬於一個ACAccountStore對象。”。 我認為這意味着如果我不保留我的ACAccount實例派生的ACAccountStore實例,那么在某些時候可能會出現問題。

讓我知道這是否有幫助,完全錯誤,或者有人可以解釋這里真正發生的事情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM