使用 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];

    }
}

最佳答案

当前版本的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;

希望这可以帮助!

关于ios - FHSTwitterEngine图片未发布,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22910951/

10-10 21:06