1

使用FHStwitterEngine发布图像会返回错误但是如果我在没有 imahe 的情况下发布推文,则它会成功发布

-(void)postTweet:(NSString*)message withImage:(UIImage*)img {

dispatch_async(GCDBackgroundThread, ^{
    @autoreleasepool {
        NSString *strMsg =[NSString stringWithFormat:@"%@",message];
        NSData *imgData =UIImagePNGRepresentation(img);
        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
        NSError *returnCode = [[FHSTwitterEngine sharedEngine]postTweet:strMsg withImageData:imgData];


        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

        NSString *title = nil;
        NSString *message = nil;


        if (returnCode) {
            title = [NSString stringWithFormat:@"Error %d",returnCode.code];
            message = returnCode.localizedDescription;

        } else {
            title = @"Tweet Posted";
            message = message;
        }

        dispatch_sync(GCDMainThread, ^{
            @autoreleasepool {
                UIAlertView *av = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [av show];
            }
        });
    }
});

}

- (IBAction)btnPost:(id)sender {

    NSString *str =@"Test5";
    UIImage *image =[UIImage imageNamed:@"contact.png"];
    if (image ==nil) {
        [self postTweet:str];
    }else {

    [self postTweet:str withImage:image];

    }
}
4

1 回答 1

0

当前版本的 FHSTwitterEngine 和发布图像存在问题。我在我的应用程序中遇到了同样的问题,但能够使用这个分叉版本的更新来解决它:

https://github.com/alvani/FHSTwitterEngine/blob/master/FHSTwitterEngine/FHSTwitterEngine.m

将其复制/粘贴到 FHSTwitterEngine.m 是最简单的,但以下是您需要的特定更改:

在 1599 号线或附近:

- (NSError *)sendPOSTRequestForURL:(NSURL *)url andParams:(NSDictionary *)params
...
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n",key] dataUsingEncoding:NSUTF8StringEncoding]];        
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:data];

在下面添加以下代码:

if ([obj isKindOfClass:[NSData class]]) {
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
}

在 688 号线或附近:

- (NSError *)postTweet:(NSString *)tweetString withImageData:(NSData *)theData inReplyTo:(NSString *)irt {
...
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"media[]"] = theData;

在下面添加以下代码:

params[@"status"] = tweetString;

希望这可以帮助!

于 2014-04-16T18:03:36.800 回答