nst / STTwitter

A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1
BSD 3-Clause "New" or "Revised" License
999 stars 161 forks source link

- (void)postMediaUpload:(NSURL *)mediaURL crashes! #134

Closed Elmundo closed 9 years ago

Elmundo commented 9 years ago

I can tweet without any problem. But when i try to post tweet with image, this method crashes. The stack is below:

[NSCFString enumerateByteRangesUsingBlock:]: unrecognized selector sent to instance 0x7f93ee653190 2014-11-04 14:21:43.781 Proveit[3324:96754] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString enumerateByteRangesUsingBlock:]: unrecognized selector sent to instance 0x7f93ee653190' *\ First throw call stack: ( 0 CoreFoundation 0x000000010aec23f5 exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010800abb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010aec950d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010ae217fc __forwarding** + 988 4 CoreFoundation 0x000000010ae21398 _CF_forwarding_prep_0 + 120 5 Foundation 0x0000000108e7d638 -[NSConcreteMutableData appendData:] + 82 6 Proveit 0x0000000107af612d +[STHTTPRequest multipartContentWithBoundary:data:fileName:parameterName:mimeType:] + 1037 7 Proveit 0x0000000107af6ff4 -[STHTTPRequest requestByAddingCredentialsToURL:] + 3460

nst commented 9 years ago

Could you please post the calling code?

You're probably using a string where the API expects data.

Elmundo commented 9 years ago

Hi,

I was busy with the project so i could not respond quickly, sorry for that.

The code is below which i tested for both sending tweet and image uploading.

// CALLING CODE //
[_twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
    NSString *tweet = @"Test Tweet";
    NSURL *imageURL = [NSURL URLWithString:@"http://upload.wikimedia.org/wikipedia/en/5/50/NES_Super_Mario_Bros.png"];
    [_twitter postMediaUpload:imageURL uploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {

    } successBlock:^(NSDictionary *imageDictionary, NSString *mediaID, NSString *size) {

        NSArray *mediaList = [NSArray arrayWithObject:mediaID];

        [_twitter postStatusUpdate:tweet
                    mediaDataArray:mediaList
                 possiblySensitive:nil
                 inReplyToStatusID:nil
                          latitude:nil
                         longitude:nil
                           placeID:nil
                displayCoordinates:nil
               uploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
                   NSLog(@"On Progress");
               } successBlock:^(NSDictionary *status) {
                   NSLog(@"status: %@", [status description]);
               } errorBlock:^(NSError *error) {
                   NSLog(@"error: %@",error.description);
               }];

    } errorBlock:^(NSError *error) {
        NSLog(@"error: %@", error.description);
    }];

} errorBlock:^(NSError *error) {
    NSLog(@"asdasd");
}];

// CRASH LOG //
-[__NSCFString enumerateByteRangesUsingBlock:]: unrecognized selector sent to instance 0x1661e700
2014-11-17 10:22:23.792 Proveit[985:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString enumerateByteRangesUsingBlock:]: unrecognized selector sent to instance 0x1661e700'
*** First throw call stack:
(0x30b82f83 0x3b3fdccf 0x30b86917 0x30b85203 0x30ad4768 0x314c31c7 0x298bcd 0x299927 0x29db6d 0x2e6adf 0x2e63f7 0x2a2c95 0x2a9627 0xe92d1 0x2d8125 0x2a2e47 0x2e6d99 0x2952cf 0x29f545 0x314c2fc3 0x314c2f07 0x314c2e21 0x307e90e7 0x307e7cf7 0x30ab68f1 0x3077f6bb 0x3077f579 0x3077f40d 0x30b4e20b 0x30b4d6db 0x30b4becf 0x30ab6ebf 0x30ab6ca3 0x35a10663 0x3340314d 0x11257d 0x3b90aab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
nst commented 9 years ago

The imageURL should be the URL of a local image.

Use -[NSURL fileURLWithPath:].

I agree that the API is not clear. It should probably be changed into postMediaUploadWithLocalURL:

Elmundo commented 9 years ago

I did as you said but still not working. Now getting this error:

error: Error Domain=STTwitterTwitterErrorDomain Code=0 "[PNG] Invalid first chunk." UserInfo=0x156bc170 {NSUnderlyingError=0x15697620 "HTTP Status 400: Bad Request", NSLocalizedDescription=[PNG] Invalid first chunk.}

[_twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"MGInstagramPhoto" ofType:@"png"];
    NSURL *imageLocalURL = [NSURL fileURLWithPath:path isDirectory:YES];

    [_twitter postMediaUpload:imageLocalURL uploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
        NSLog(@"asdasd");
    } successBlock:^(NSDictionary *imageDictionary, NSString *mediaID, NSString *size) {

        NSArray *mediaList = [NSArray arrayWithObject:mediaID];

        [_twitter postStatusUpdate:@"Test Message"
                    mediaDataArray:mediaList
                 possiblySensitive:nil
                 inReplyToStatusID:nil
                          latitude:nil
                         longitude:nil
                           placeID:nil
                displayCoordinates:nil
               uploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
                   NSLog(@"error");
               } successBlock:^(NSDictionary *status) {
                   NSLog(@"status: %@", [status description]);
               } errorBlock:^(NSError *error) {
                   NSLog(@"error");
               }];
    } errorBlock:^(NSError *error) {
        NSLog(@"error: %@", error.description);
    }];

} errorBlock:^(NSError *error) {
    NSLog(@"error");
}];