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

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

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

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

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

Q&A

解決済

1回答

617閲覧

swift DKImagePickerControllerの使い方

mars111

総合スコア24

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

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

1グッド

0クリップ

投稿2022/07/11 07:17

問題点

複数選択の行えるカメラロールを使用したいと思い、こちらのサイトを参考にしているのですが、このサイトに記載されている一覧のコードをどこに記述していいのかわからず、苦戦しています。
UIImagePickerと同様に記述すればいいのかと思い、以下のコードのように書いてみたのですが、Thread 5: signal SIGABRTとのエラーが出てしまいます
色々とデバックをしたところ、openImagePicker内の

swift

1 self.present(picker, animated: true, completion: nil)

で問題が生じているようです
よろしくお願いいたします

コード全文

swift

1 2import UIKit 3import RealmSwift 4import DKImagePickerController 5 6 7 8class AddModuleViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 9 10 @IBOutlet weak var countImage: UILabel! 11 @IBOutlet weak var titleTextField: UITextField! 12 13 var moduleName = "" 14 var imageCount = 0 15 16 var imageList:[UIImage] = [] 17 18 let realm = try! Realm() 19 20 21 22 override func viewDidLoad() { 23 super.viewDidLoad() 24 25 // Do any additional setup after loading the view. 26 27 28 } 29 30 31 @IBAction func openImagePicker(_ sender: Any) { 32 if imageList.count < imageCount{ 33 let picker = DKImagePickerController() 34 picker.delegate = self 35 picker.maxSelectableCount = imageCount - imageList.count 36 //カメラモード、写真モードの選択 37 picker.sourceType = .photo 38 //キャンセルボタンの有効化 39 picker.showsCancelButton = true 40 print("call") 41 //UIのカスタマイズ 42 picker.didSelectAssets = { (assets: [DKAsset]) in 43 for asset in assets { 44 asset.fetchFullScreenImage(completeBlock: { (image, info) in 45 self.imageList.append(image!) 46 print(image!) 47 }) 48 } 49 } 50 self.present(picker, animated: true, completion: nil) 51 }else{ 52 let dialog = UIAlertController(title: "画像数が上限に達しています", message: "このモジュールの最大画像枚数は\(imageCount)枚です。より多くの画像を追加したい場合は他のモジュールを選択してください。", preferredStyle: .alert) 53 dialog.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) 54 55 // 生成したダイアログを実際に表示します 56 self.present(dialog, animated: true, completion: nil) 57 } 58 59 60 } 61 62 @IBAction func saveAlbum(_ sender: Any) { 63 print(imageList) 64 65 66 } 67 68 69 func getFileURL(fileName: String) -> URL { 70 let docDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! 71 return docDir.appendingPathComponent(fileName) 72 } 73 74} 75 76

エラー

swift

12022-07-11 15:59:50.614376+0900 ARalbum[73419:11990240] [LayoutConstraints] Unable to simultaneously satisfy constraints. 2 Probably at least one of the constraints in the following list is one you don't want. 3 Try this: 4 (1) look at each constraint and try to figure out which you don't expect; 5 (2) find the code that added the unwanted constraint or constraints and fix it. 6( 7 "<NSLayoutConstraint:0x28233ead0 UILabel:0x10361f7d0.height == 50 (active)>", 8 "<NSLayoutConstraint:0x28233e990 UILabel:0x10361f7d0.top == UITableViewCellContentView:0x10361f430.topMargin (active)>", 9 "<NSLayoutConstraint:0x28233e940 UITableViewCellContentView:0x10361f430.bottomMargin == UILabel:0x10361f7d0.bottom (active)>", 10 "<NSLayoutConstraint:0x28233e800 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x283916840'UIViewLayoutMarginsGuide']-(11)-| (active, names: '|':UITableViewCellContentView:0x10361f430 )>", 11 "<NSLayoutConstraint:0x28233f890 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x10361f430.height == 72.5 (active)>", 12 "<NSLayoutConstraint:0x28233e8f0 'UIView-topMargin-guide-constraint' V:|-(11)-[UILayoutGuide:0x283916840'UIViewLayoutMarginsGuide'] (active, names: '|':UITableViewCellContentView:0x10361f430 )>" 13) 14 15Will attempt to recover by breaking constraint 16<NSLayoutConstraint:0x28233ead0 UILabel:0x10361f7d0.height == 50 (active)> 17 18Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 19The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 20<UIImage:0x28321a010 anonymous {3024, 4032} renderingMode=automatic> 212022-07-11 15:59:50.700891+0900 ARalbum[73419:11990240] [LayoutConstraints] Unable to simultaneously satisfy constraints. 22 Probably at least one of the constraints in the following list is one you don't want. 23 Try this: 24 (1) look at each constraint and try to figure out which you don't expect; 25 (2) find the code that added the unwanted constraint or constraints and fix it. 26( 27 "<NSLayoutConstraint:0x28233f390 UIImageView:0x10362e000.width == 1.875*UIImageView:0x10362e000.height (active)>", 28 "<NSLayoutConstraint:0x28233e760 UILabel:0x10362e1e0.height == 25 (active)>", 29 "<NSLayoutConstraint:0x28233f8e0 H:[UIImageView:0x10362e000]-(0)-| (active, names: '|':UITableViewCellContentView:0x10362de60 )>", 30 "<NSLayoutConstraint:0x28233f930 V:|-(0)-[UIImageView:0x10362e000] (active, names: '|':UITableViewCellContentView:0x10362de60 )>", 31 "<NSLayoutConstraint:0x28233fc50 H:|-(0)-[UIImageView:0x10362e000] (active, names: '|':UITableViewCellContentView:0x10362de60 )>", 32 "<NSLayoutConstraint:0x28233fcf0 V:[UIImageView:0x10362e000]-(5)-[UILabel:0x10362e1e0] (active)>", 33 "<NSLayoutConstraint:0x28233fe30 UITableViewCellContentView:0x10362de60.bottomMargin == UILabel:0x10362e1e0.bottom + 5 (active)>", 34 "<NSLayoutConstraint:0x28233bde0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x2839171e0'UIViewLayoutMarginsGuide']-(11)-| (active, names: '|':UITableViewCellContentView:0x10362de60 )>", 35 "<NSLayoutConstraint:0x28233ba20 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x10362de60.height == 246.5 (active)>", 36 "<NSLayoutConstraint:0x28233b9d0 'UIView-Encapsulated-Layout-Width' UITableViewCellContentView:0x10362de60.width == 375 (active)>" 37) 38 39Will attempt to recover by breaking constraint 40<NSLayoutConstraint:0x28233e760 UILabel:0x10362e1e0.height == 25 (active)> 41 42Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 43The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 44call 452022-07-11 15:59:54.338829+0900 ARalbum[73419:11990291] [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data. 46dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib:/usr/lib/libMTLCapture.dylib 47(lldb)
q22r5695👍を押しています

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

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

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

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

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

mars111

2022/07/11 08:00

解決しました! すでにUIImagePickerが使えていたので不要かと思っていました。 ありがとうございます
guest

回答1

0

自己解決

Info.plist にフォトライブラリへのアクセス許可を求めるメッセージ (NSPhotoLibraryUsageDescription) を追加する必要がありました。 https://app-knowledge.work/how-to-access

投稿2022/07/11 08:00

mars111

総合スコア24

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問