iOs OAuth图像后期处理&x2B;状态更新问题

iOs OAuth图像后期处理&x2B;状态更新问题,ios,twitter,Ios,Twitter,我正在尝试使用图像发布状态 图像正在上载,但状态文本丢失 为什么文字没有发布???? 这是我的后处理程序 - (NSString *)_sendRequestWithMethod:(NSString *)method path:(NSString *)path queryParameters:(NSDictionary *)params body:(N

我正在尝试使用图像发布状态

图像正在上载,但状态文本丢失

为什么文字没有发布???? 这是我的后处理程序

- (NSString *)_sendRequestWithMethod:(NSString *)method
                            path:(NSString *)path
                 queryParameters:(NSDictionary *)params
                            body:(NSString *)body
                     requestType:(MGTwitterRequestType)requestType
                    responseType:(MGTwitterResponseType)responseType {
NSURL *finalURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update_with_media.json"];
if (!finalURL) {
    return nil;
}

OAMutableURLRequest *theRequest =  [[[OAMutableURLRequest alloc]
                                     initWithURL:finalURL
                                     consumer:self.consumer
                                     token:_accessToken
                                     realm:nil
                                     signatureProvider:nil] autorelease];

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *itemImageStr = [prefs stringForKey:@"socialImage"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
UIImage *thImage;
NSString *filePath = [documentsDir stringByAppendingFormat:@"/%@",itemImageStr];
thImage = [UIImage imageWithContentsOfFile:filePath];
if (thImage==nil)
{
    NSString *fileLoc = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@",itemImageStr] ofType:nil];
    thImage = [UIImage imageWithContentsOfFile:fileLoc];
}
if (thImage==nil) thImage = [UIImage imageNamed:@"tNoImage.jpg"];

NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"twitterBlue.png"]);
[theRequest setHTTPMethod:@"POST"];
[theRequest setTimeoutInterval:120];
[theRequest setHTTPShouldHandleCookies:NO];

[theRequest setValue:_clientName    forHTTPHeaderField:@"X-Twitter-Client"];
[theRequest setValue:_clientVersion forHTTPHeaderField:@"X-Twitter-Client-Version"];
[theRequest setValue:_clientURL     forHTTPHeaderField:@"X-Twitter-Client-URL"];
NSString *boundary = @"--0246824681357ACXZabcxyziMenuTechmeticsdjskjdhf";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[theRequest setValue:contentType forHTTPHeaderField:@"content-type"];

NSMutableData *fbody = [NSMutableData data];

//Status
[fbody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"--%@\r\n\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"status\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"Test status message 293102938"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

// media
[fbody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"media[]\"; filename=\"1.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
//[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[NSData  dataWithData:imageData]];
[fbody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
//
[fbody appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[theRequest prepare];
[theRequest setHTTPBody:fbody];



MGTwitterHTTPURLConnection *connection;
connection = [[MGTwitterHTTPURLConnection alloc] initWithRequest:theRequest
                                                        delegate:self
                                                     requestType:requestType
                                                    responseType:responseType];
if (!connection) {
    return nil;
} else {
    [_connections setObject:connection forKey:[connection identifier]];
    [connection release];
}
return [connection identifier];
}我已经解决了这个问题。 工作代码:

- (NSString *)_sendRequestWithMethod:(NSString *)method
                            path:(NSString *)path
                 queryParameters:(NSDictionary *)params
                            body:(NSString *)body
                     requestType:(MGTwitterRequestType)requestType
                    responseType:(MGTwitterResponseType)responseType {
NSURL *finalURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update_with_media.json"];
if (!finalURL) {
    return nil;
}

OAMutableURLRequest *theRequest =  [[[OAMutableURLRequest alloc]
                                     initWithURL:finalURL
                                     consumer:self.consumer
                                     token:_accessToken
                                     realm:nil
                                     signatureProvider:nil] autorelease];

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *itemImageStr = [prefs stringForKey:@"socialImage"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
UIImage *thImage;
NSString *filePath = [documentsDir stringByAppendingFormat:@"/%@",itemImageStr];
thImage = [UIImage imageWithContentsOfFile:filePath];
if (thImage==nil)
{
    NSString *fileLoc = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@",itemImageStr] ofType:nil];
    thImage = [UIImage imageWithContentsOfFile:fileLoc];
}
if (thImage==nil) thImage = [UIImage imageNamed:@"tNoImage.jpg"];

NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"twitterBlue.png"]);
[theRequest setHTTPMethod:@"POST"];
[theRequest setTimeoutInterval:120];
[theRequest setHTTPShouldHandleCookies:NO];

//[theRequest setValue:_clientName    forHTTPHeaderField:@"X-Twitter-Client"];
//[theRequest setValue:_clientVersion forHTTPHeaderField:@"X-Twitter-Client-Version"];
//[theRequest setValue:_clientURL     forHTTPHeaderField:@"X-Twitter-Client-URL"];
NSString *boundary = @"--0246824681357ACXZabcxyziMenuTechmeticsdjskjdhf";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[theRequest setValue:contentType forHTTPHeaderField:@"content-type"];

NSMutableData *fbody = [NSMutableData data];

//Status
[fbody appendData:[[NSString stringWithFormat:@"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"status\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"Test status message 293102938"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

// media
[fbody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"media[]\"; filename=\"1.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
//[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[fbody appendData:[NSData  dataWithData:imageData]];
[fbody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
//
[fbody appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[theRequest prepare];
[theRequest setHTTPBody:fbody];


NSString *rBody = [[NSString alloc] initWithData:theRequest.HTTPBody encoding:NSUTF8StringEncoding];
NSLog(rBody);

MGTwitterHTTPURLConnection *connection;
connection = [[MGTwitterHTTPURLConnection alloc] initWithRequest:theRequest
                                                        delegate:self
                                                     requestType:requestType
                                                    responseType:responseType];
if (!connection) {
    return nil;
} else {
    [_connections setObject:connection forKey:[connection identifier]];
    [connection release];
}
return [connection identifier];

}

谢谢分享信息:)