2016-12-27 20 views
0

ここで私はいずれかがここから画像をアップロードするために私を助けることができ、自分のチャットアプリケーションのためのiOSのXMPPライブラリ(https://github.com/processone/demo-xmpp-ios)を使用していますが、私は、サードパーティのサーバーに画像をアップロードしてからURLを送る勧めイメージや写真をejabberd XMPP Webサーバーにアップロードする方法は?

答えて

0

をlibrary.thanks XMPP経由で

無料のファイルアップロードを20GB提供するBackendlessを使用した例です。あなたはまた、彼らのSDKおよびセットアップAPIキーをインストールするには、Backendlessドキュメントに従わなければならないでしょう:

[backendless.fileService.permissions grantForAllRoles:fileName operation:FILE_READ]; 
[backendless.fileService saveFile:fileName content:file response:^(BackendlessFile * file) { 

    // We have the url so we can send the message 

} error:^(Fault * fault) { 
}]; 

またはAFNetworkingを使用してPHPサーバへ:

NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:_url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { 
    [formData appendPartWithFileData:file name:@"upfile" fileName:name mimeType:mimeType]; 
} error:nil]; 

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; 

NSURLSessionUploadTask *uploadTask; 
uploadTask = [manager 
       uploadTaskWithStreamedRequest:request 
       progress:^(NSProgress * _Nonnull uploadProgress) { 
        // This is not called back on the main queue. 
        // You are responsible for dispatching to the main queue for UI updates 
        dispatch_async(dispatch_get_main_queue(), ^{ 
         //Update the progress view       
         [progressView setProgress:uploadProgress.fractionCompleted]; 
        }); 
       } 
       completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { 
        if (error) { 
        } else { 
         NSString *filePath = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; 

         // Send message here 

        } 
       }]; 

[uploadTask resume]; 

次に、あなたは画像やサムネイルのURLを追加することができますそして、XMPPメッセージに画像寸法:画像はopeneことができるように、

[xmppMessage addBody:imageURL]; 
    [xmppMessage addAttributeWithName:bMessageImageURL stringValue:imageURL]; 
    [xmppMessage addAttributeWithName:bMessageThumbnailURL stringValue:thumbnailURL]; 
    [xmppMessage addAttributeWithName:bMessageImageWidth floatValue:width.floatValue]; 
    [xmppMessage addAttributeWithName:bMessageImageHeight floatValue:height.floatValue]; 

は私がimageURLに身体を設定することをお勧めしたいですdを標準のXMPPクライアントから取得します。メッセージが受信されると、次のように

、再度詳細にアクセスすることができます

NSString * imageURL = [[message attributeForName:bMessageImageURL] stringValue]; 
    NSString * thumbnailURL = [[message attributeForName:bMessageThumbnailURL] stringValue]; 
    float width = [[[message attributeForName:bMessageImageWidth] stringValue] floatValue]; 
    float height = [[[message attributeForName:bMessageImageHeight] stringValue] floatValue]; 

あなたはその後、SDWebImageを使用して画像を表示することができます。

iOSのフルフロントエンドメッセージングインターフェイスであるChatSDKもお勧めします。イメージメッセージを表示するためのUITableViewセルが含まれています。私はXMPPFrameworkを使ってXMPPメッセンジャーを構築しました。

+0

あなたの答えは正しいかもしれませんが、問題は "客観的な"ではなく "迅速な"とタグ付けされているので、これはむしろ話題にはなりません.../ – Moritz

+0

ああ、タイトルに指定されていません。私はSwift版を提供しようとします。 –

+0

言語はタイトルには決して*置かれてはいけません。実際にはその場所はタグの中にあります。常に。 //ありがとう。 :) – Moritz

関連する問題