【问题标题】:This application is modifying the autolayout engine from a background thread Twitter Background Share此应用程序正在从后台线程 Twitter Background Share 修改自动布局引擎
【发布时间】:2016-06-20 22:01:27
【问题描述】:

我试图在 Twitter 上分享文本。将文本发布到 Twitter 后,我收到错误:此应用程序正在从后台线程修改自动布局引擎,这可能导致引擎损坏和奇怪的崩溃。这将在未来的版本中导致异常。对此有什么解决方案?

ACAccountStore *account = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:[NSString stringWithFormat:@"text with link http://www.pothi.com/"],@"status",@"true",@"wrap_links", nil];
    //hear before posting u can allow user to select the account

    NSArray *arrayOfAccons = [account accountsWithAccountType:accountType];
    for(ACAccount *acc in arrayOfAccons)
    {
        NSLog(@"%@",acc.username); //in this u can get all accounts user names provide some UI for user to select,such as UITableview
    }

    [account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
    {
        if (granted == YES)
        {
            // Populate array with all available Twitter accounts
            NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
            if ([arrayOfAccounts count] > 0)
            {
                //use the first account available
                ACAccount *acct = [arrayOfAccounts objectAtIndex:0]; //hear this line replace with selected account. than post it :)
                //Build a twitter request
                SLRequest *postRequest  = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                                             requestMethod:SLRequestMethodPOST
                                                                       URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"]
                                                                parameters:dict];
                //for iOS 6 use "https://api.twitter.com/1/statuses/update.json"
                //u should get the response code 200 for successful post
                [postRequest setAccount:acct];
                //manage the response
                [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
                 {
                     if(error)
                     {
                         //if there is an error while posting the tweet
                         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"Error in posting" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                         [alert show];
                     }
                     else
                     {
                         // on successful posting the tweet
                         NSLog(@"Twitter response, HTTP response: %li", (long)[urlResponse statusCode]);
                         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"Successfully posted" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                         [alert show];
                     }
                 }];
            }
            else
            {
                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"You have no twitter account" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
            }
        }
        else
        {
            //suppose user not set any of the accounts
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"Permission not granted" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }
    }];

【问题讨论】:

  • 你在哪一行得到这个错误
  • 发布成功后,所有 UIAlertView - Anbu.Karthik

标签: ios objective-c ios7 ios9 xcode7


【解决方案1】:

Apple 已开始(使用 iOS 9)检测您何时执行此操作并警告您。在后台执行其他操作的同时更新 UI 之前,将 UI 更新调用封装在类似

在主线程中调用你所有的UIAlertview 并检查

dispatch_async(dispatch_get_main_queue(), ^{
// add your UIAlertview code here
});

【讨论】:

  • 我的 Skype id 是 karthik.saral@gmail.com,但大多数时候我不来 Skype。
  • 我向你的 Skype 发出了请求。一旦你接受它。 POTHIRAJ_BSETEC
  • 肯定和你在钦奈
  • 没有。 Rajapalayam - 靠近马杜赖
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-23
  • 1970-01-01
  • 1970-01-01
  • 2017-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多