0

我正在制作一个应用程序,用户可以在其中聊天并从该应用程序发送文件。但是我坚持用户可以通过附件将任何文件发送给其他用户,但我没有找到任何示例应用程序或帮助代码,所以任何人都可以帮助我解决我的问题。

告诉我一些示例应用程序链接以及通过使用应用程序从 iPhone 浏览文件来上传和发送文件的技术。

4

2 回答 2

0

让我先给你一些建议,像这样从设备上传文件

1.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{


NSString *mediaType = info[UIImagePickerControllerMediaType];

if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
 {
    // Media is an image
    picImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/image.jpg"]];

    filePath = imagePath;
    [UIImageJPEGRepresentation(picImage, 1.0) writeToFile:imagePath atomically:YES];
    arrayMute = (NSMutableArray*) [self sendData:filePath]  
 }
}

2 现在只需通过 ASIFormDataRequest 将媒体上传到网络服务,然后他们将生成链接并返回给链接。然后你可以通过 xmpp 将该链接发送给另一个用户。然后其他用户可以下载该媒体。

-(NSMutableArray*)sendData:(NSString*)multiMData
{
  ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://194.158.1.25/IphoneVideoService/webservice.asmx/GetData1"]];

[request addRequestHeader: @"Content-Type" value:
 @"application/x-www-form-urlencoded"];

[request setDelegate:self];

[request setDidFailSelector:@selector(uploadFailed:)];

[request setUploadProgressDelegate:progressToDownload];

[request setDidFinishSelector:@selector(uploadFinished:)];

[request setDidFinishSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(requestFinished:)];

[request setShouldContinueWhenAppEntersBackground:YES];

NSString *url = [[NSURL fileURLWithPath:multiMData] path];

    [request setFile:url withFileName:[NSString stringWithFormat:@"Hello.jpeg"] andContentType:@"image/jpeg" forKey:@"file"];

[request setTimeOutSeconds:50000];
[request setRequestMethod:@"POST"];

[request startSynchronous];


SBJSON *sbJason = [[SBJSON alloc] init];

NSMutableArray *getUploadArray = [sbJason objectWithString:responseForMedia];

return getUploadArray;


 }
于 2013-05-09T06:03:44.950 回答
0

实现这一目标的一些建议

浏览

上传

聊天

于 2013-05-09T05:38:40.040 回答