質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

SNS

SNS(ソーシャル・ネットワーキング・サービス)は、 人と人とのつながりを促進したり、サポートしたりすることが可能なコミュニティ型のWebサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

0回答

671閲覧

AWSS3を用いたiOSアプリの画像配信について

daigororo

総合スコア9

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

SNS

SNS(ソーシャル・ネットワーキング・サービス)は、 人と人とのつながりを促進したり、サポートしたりすることが可能なコミュニティ型のWebサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

1クリップ

投稿2020/02/29 02:14

編集2020/02/29 02:33

もし分かる方がいらっしゃいましたら、教えていただきたいです。

私は今、システムアーキテクチャをAWSに依存したiOSモバイルアプリを趣味で開発しています。
写真投稿型SNS(Instagram)のようなものを作ってみたいと思い、
投稿する画像をAWSS3に格納し、それに紐付けたメタデータをAWSDynamoDBに保存しています。
投稿した画像を、例えばタイムラインを見れるようにするために、AWSDynamoDBからメタデータを取ってきて、
(そのメタデータの中に画像のkeyも含まれています)画像をダウンロードして、UITableViewの各セルに表示しているのですが、画像が表示されるまでの時間が遅かったり、同じ画像がいくつも表示されることがあります。

swift

1 2 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 3 let cell = tableView.dequeueReusableCell(withIdentifier: "TimelineTableViewCell", for: indexPath) as! TimelineTableViewCell 4 5 cell.PostID = list[indexPath.row].id 6 cell.CognitoID = list[indexPath.row].CognitoID 7 cell.UserNameLabel.text = list[indexPath.row].CognitoUserName 8 cell.ProfileImageName = list[indexPath.row].ProfileImage 9 cell.PostTextView.text = list[indexPath.row].PostComment 10 cell.YearAndDate = list[indexPath.row].PostedDate 11 cell.Time = list[indexPath.row].PoetedTime 12 cell.LikeCountLabel.text = String(list[indexPath.row].LikeCount) 13 cell.CommentCountLabel.text = String(list[indexPath.row].CommentCount) 14 15 16 cell.ProfileImageButton.tag = indexPath.row 17 cell.ProfileImageButton.addTarget(self, action: #selector(ProfileImageButton(_:)), for: .touchUpInside) 18 19 /* cell.LikeButton.tag = indexPath.row 20 cell.LikeButton.addTarget(self,action: #selector(LikeButtonAction(_:)), for: .touchUpInside) */ 21 22 23 let expressionPost = AWSS3TransferUtilityDownloadExpression() 24 expressionPost.progressBlock = {(task, progress) in 25 DispatchQueue.main.async(execute: { 26 }) 27 } 28 29 transferUtilityPost.downloadData( 30 forKey: cell.CognitoID + cell.YearAndDate + cell.Time, 31 expression: expressionPost, 32 completionHandler: completionHandlerPost).continueWith { (task) -> AnyObject? in 33 if let error = task.error { 34 NSLog("Error: %@",error.localizedDescription); 35 DispatchQueue.main.async(execute: { 36 }) 37 } 38 if let _ = task.result { 39 DispatchQueue.main.async(execute: { 40 }) 41 NSLog("Download Starting!") 42 } 43 return nil; 44 } 45 46 self.completionHandlerPost = { (task, location, data, error) -> Void in 47 DispatchQueue.main.async(execute: { 48 if let error = error { 49 NSLog("Failed with error: (error)") 50 } 51 else{ 52 cell.PostImage.image = UIImage(data: data!) 53 } 54 }) 55 } 56 57 let expressionPostPro = AWSS3TransferUtilityDownloadExpression() 58 expressionPostPro.progressBlock = {(task, progress) in 59 DispatchQueue.main.async(execute: { 60 }) 61 } 62 63 transferUtilityPostPro.downloadData( 64 forKey: cell.ProfileImageName, 65 expression: expressionPostPro, 66 completionHandler: completionHandlerPostPro).continueWith { (task) -> AnyObject? in 67 if let error = task.error { 68 NSLog("Error: %@",error.localizedDescription); 69 DispatchQueue.main.async(execute: { 70 }) 71 } 72 if let _ = task.result { 73 DispatchQueue.main.async(execute: { 74 }) 75 NSLog("Download Starting!") 76 } 77 return nil; 78 } 79 80 self.completionHandlerPostPro = { (task, location, data, error) -> Void in 81 DispatchQueue.main.async(execute: { 82 if let error = error { 83 NSLog("Failed with error: (error)") 84 } 85 else{ 86 cell.ProfileImage.image = UIImage(data: data!) 87 } 88 }) 89 } 90 91 return cell 92 93 }

該当のソースコードは上記の通りなのですが問題点として推測しているのが、
「そもそも上記のコードがうまく表示されない原因を作っている」 (swiftの関数や書き方次第で問題解決する)
「画像ダウンロードに関して、もっとうまい方法がある」(システムのバックエンドをもう一度見直す必要がある)

のどちらかだと考えています。
画像がうまく表示されないのは、画像ダウンロードの遅さゆえと疑い、試しに高速配信をさせてみようと思い、
AWSCloudFrontを用いようと思いましたが、モバイルに配信する場合のやり方もよくわかりません。

もしお詳しい方がいらっしゃいましたら、教えていただきたいです。
よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問