FHSTwitterEngine图片没有发布

时间:2014-04-07 11:21:31

标签: ios objective-c twitter fhs-twitter-engine

使用 FHStwitterEngine 发布图片时返回错误但如果我发布的推文没有成功发布

-(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];

    }
}

1 个答案:

答案 0 :(得分: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;

希望这有帮助!