1
votes

I am trying to post a picture from my app to twitter account. It works fine on my 3 devices but crashes for one of my friends. I am using the following code.. Wasted almost 2 days on it so far without any luck. Please see the Problem lines, app crashes on those two lines as per crashalytics. Any one has experienced this?

NSString *account_id = [PFUser currentUser][@"Twitter_ScreenName"];

            NSURL *retweetURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update_with_media.json"];
            //Problem
            NSDictionary *params = @{@"status" : [NSString stringWithFormat:@"%@#mytag",self.postTextView.text]};
            SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                                    requestMethod:SLRequestMethodPOST
                                                              URL:retweetURL
                                                       parameters:params];
            NSData *imageData = UIImageJPEGRepresentation(self.postImage, 0.5f);
            [request addMultipartData:imageData withName:@"media[]" type:@"image/jpeg" filename:@"image.jpg"];

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

            [account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
             {
                 if (granted == YES)//Problem
                 {
                     NSArray *twitterAccounts =
                     [account accountsWithAccountType:accountType];


                     if ([twitterAccounts count] > 0)
                     {
                         ACAccount *twitterAccount;

                         for (int i=0; i<[twitterAccounts count]; i++)
                         {
                             ACAccount *acc=[twitterAccounts objectAtIndex:i];
                             if ([acc.username isEqualToString: account_id ])
                             {
                                 twitterAccount = acc;
                                 break;

                             }
                         }

Crash Logs: Thread : Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x2d8eaecb exceptionPreprocess + 130 1 libobjc.A.dylib 0x38085ce7 objc_exception_throw + 38 2 CoreFoundation 0x2d8ee7f7 -[NSObject(NSObject) doesNotRecognizeSelector:] + 202 3 CoreFoundation 0x2d8ed0f7 ___forwarding_ + 706 4 CoreFoundation 0x2d83c058 _CF_forwarding_prep_0 + 24 5 MyApp 0x0011d425 44-[HMTagListViewController buttonAddClicked:]_block_invoke_3 (HMTagListViewController.m:2475) 6 libdispatch.dylib 0x38574b3b _dispatch_barrier_sync_f_slow_invoke + 70 7 libdispatch.dylib 0x3856ed3f _dispatch_client_callout + 22 8 libdispatch.dylib 0x385716c3 _dispatch_main_queue_callback_4CF + 278 9 CoreFoundation 0x2d8b5641 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 8 10 CoreFoundation 0x2d8b3f0d __CFRunLoopRun + 1308 11 CoreFoundation 0x2d81e729 CFRunLoopRunSpecific + 524 12 CoreFoundation 0x2d81e50b CFRunLoopRunInMode + 106 13 GraphicsServices 0x3278d6d3 GSEventRunModal + 138 14 UIKit 0x3017f871 UIApplicationMain + 1136 15 MyApp 0x000edabf main (main.m:16) 16 libdyld.dylib 0x38583ab7 start + 2

====================

Thread : SLRequest performRequest queue 0 libsystem_kernel.dylib 0x38627aa0 semaphore_wait_trap + 8 1 libsystem_platform.dylib 0x3869ba0d _os_semaphore_wait + 12 2 libdispatch.dylib 0x38573513 _dispatch_barrier_sync_f_slow + 138 3 MyApp 0x0011d31b __44-[HMTagListViewController buttonAddClicked:]_block_invoke_21179 (HMTagListViewController.m:2461) 4 Social 0x2ff74267 __39-[SLRequest performRequestWithHandler:]_block_invoke + 410 5 libdispatch.dylib 0x3856ed53 _dispatch_call_block_and_release + 10 6 libdispatch.dylib 0x38573cbd _dispatch_queue_drain + 488 7 libdispatch.dylib 0x38570c6f _dispatch_queue_invoke + 42 8 libdispatch.dylib 0x385745f1 _dispatch_root_queue_drain + 76 9 libdispatch.dylib 0x385748dd _dispatch_worker_thread2 + 56 10 libsystem_pthread.dylib 0x3869fc17 _pthread_wqthread + 298

1
So you basically know which line but don't seem to want to debug that line. It can easily be separated into three statements so it could be determined where the problem is. Add NSLog() statements. Why haven't you done that! Where is the stack trace the exact full (copy/paste) error message?zaph
Zaph.. either try to help people or move on. You don't have to lecture some one withyour annoying exclamations. I can't do an nslog as it's not happening in my devices but on my friends who doesn't have access to code. Stop wasting time!!!Mobilewits
Create a version for your friend with more debugging, have that person work with you. If you don't combine statements the bug reports would more clearly point to the problem. Where is the error message?zaph
What is the crash message, and which particular line is it?Enrico Susatyo

1 Answers

0
votes

I finally happened to create a simple app that just posts a media using the users Twitter account. I was able to nail down the issue, it was because of Expired Token. User's Twitter credentials were not accurate any more. When he tapped on his Twitter account in Settings, we got the alert to prove that. Once he re-entered his alerts everything started to work. Now it works in my main app as well.

Thanks everyone!