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

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

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

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

Xcode

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

Swift

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

Q&A

解決済

2回答

1853閲覧

実機シュミレーションをするとThread 1: signal SIGABRTのエラーが発生する。

PINE1103

総合スコア20

iOS

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

Xcode

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

Swift

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

0グッド

0クリップ

投稿2020/03/31 04:52

編集2020/03/31 08:03

DKImagePickerControllerという外部ライブラリを用いようとしているのですが、アプリでフォトライブラリを開こうとするとThread 1: signal SIGABRTというエラーが発生してしまいます。エミュレーターではうまくいくのですが、実機でシュミレーションをするとエラーが出てしまいます。実機はiphone11 ver 13.3.1,Xcodeのバージョンは11.3.1です。エラーが出るコードは下にあります。自分でやってみたことはビルドをcleanして再び構築、Xcode で Product > Scheme > Edit Scheme から Run Scheme のBuild Configurationを
DebugからReleaseに変える、の二つです。

swift

1import UIKit 2import DKImagePickerController 3import Photos 4 5class viewPhotoController1: UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate{ 6 7 @IBOutlet weak var collectionView1: UICollectionView! 8 9 override func viewDidLoad() { 10 super.viewDidLoad() 11 12 // Do any additional setup after loading the view 13 14 15 //directory 作成 16 let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) 17 let documetnsDirectory = paths[0] 18 let docURL = URL(string: documetnsDirectory)! 19 let datapath = docURL.appendingPathComponent("test1") 20 if !FileManager.default.fileExists(atPath: datapath.absoluteString) { 21 do { 22 try FileManager.default.createDirectory(atPath: datapath.absoluteString, withIntermediateDirectories: true, attributes: nil) 23 } catch { 24 print("フォルダの作成に失敗!,error=(error)"); 25 } 26 } 27 } 28 29 30 31 /* 32 // MARK: - Navigation 33 34 // In a storyboard-based application, you will often want to do a little preparation before navigation 35 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 36 // Get the new view controller using segue.destination. 37 // Pass the selected object to the new view controller. 38 } 39 */ 40 //画像保存 41 //画像を保存するメソッド jpegに直して保存 42 func saveImage (image: UIImage?, path: String ) -> Bool { 43 let jpgImageData = image?.jpegData(compressionQuality:0.5) 44 do { 45 try jpgImageData!.write(to: URL(fileURLWithPath: path), options: .atomic) 46 } catch { 47 print(error) 48 return false 49 } 50 return true 51 } 52 53 54 55 @IBAction func addPhoto1(_ sender: Any) { 56 //カメラかフォトライブラリどちらから画像を取得するか選択 57 let alertController = UIAlertController(title: "確認", message: "選択してください", preferredStyle: .actionSheet) 58 //まず、使用可能かを確認してからカメラ、フォトライブラリを起動するための選択肢を定義 59 if UIImagePickerController.isSourceTypeAvailable(.camera){ 60 let cameraAction = UIAlertAction(title: "カメラ", style: .default, handler: { 61 (action: UIAlertAction) in 62 //カメラを起動 63 let imagePickerController = UIImagePickerController() 64 imagePickerController.sourceType = .camera 65 imagePickerController.delegate = self 66 self.present(imagePickerController, animated: true, completion: nil) 67 68 }) 69 alertController.addAction(cameraAction) 70 } 71 if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary){ 72 let photoLibraryAction = UIAlertAction(title: "フォトライブラリー", style: .default, handler:{ 73 (action: UIAlertAction) in 74 //フォトライブラリを起動 75 let dkImagePickerController = DKImagePickerController()//ここでエラーが出ます 76 //無制限に選択可能 77 dkImagePickerController.maxSelectableCount = 0 78 dkImagePickerController.sourceType = .photo 79 dkImagePickerController.showsCancelButton = true 80 dkImagePickerController.didSelectAssets = { [unowned self] (assets: [DKAsset]) in 81 //選択された画像はassetsに入れて返却されるのでfetch して取り出す。 82 for asset in assets { 83 var i = 0 84 asset.fetchFullScreenImage(completeBlock: {(image,info) in 85 let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) 86 let documetnsDirectory = paths[0] 87 let docURL = URL(string: documetnsDirectory)! 88 let datapath = docURL.appendingPathComponent("test1") 89 let formatter = DateFormatter() 90 formatter.dateFormat = "yyyyMMddHHmmssSSS" 91 let fileURL = datapath.appendingPathComponent("myphoto-(formatter.string(from: Date()))-(i).jpg") 92 let datapathString = fileURL.absoluteString 93 //ここで取り出せる,このimageはUIImage?型 94 self.saveImage(image: image, path: datapathString) 95 }) 96 i += 1 97 } 98 } 99 self.present(dkImagePickerController, animated: true, completion: nil) 100 }) 101 alertController.addAction(photoLibraryAction) 102 } 103 //キャンセルの選択肢を定義 104 let cancelAction = UIAlertAction(title: "キャンセル", style: .cancel, handler: nil) 105 alertController.addAction(cancelAction) 106 //ipadで落ちてしまう対策 107 alertController.popoverPresentationController?.sourceView = view 108 //選択肢を画面に表示 109 present(alertController, animated: true, completion: nil) 110 111 } 112 113 //撮影が終わった時に呼ばれるdelegateメソッド 114 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { 115 //撮影が終わった時、時系列で保存することで重複を防ぐ 116 let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) 117 let documetnsDirectory = paths[0] 118 let docURL = URL(string: documetnsDirectory)! 119 let datapath = docURL.appendingPathComponent("test1") 120 let formatter = DateFormatter() 121 formatter.dateFormat = "yyyyMMddHHmmssSSS" 122 let fileURL = datapath.appendingPathComponent("myphoto-(formatter.string(from: Date()))-0.jpg") 123 let datapathString = fileURL.absoluteString 124 125 let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage 126 //撮影した画像をdocumentsに保存する 127 if saveImage(image: image, path: datapathString){ 128 //モーダルビューを閉じる 129 dismiss(animated: true, completion: nil) 130 } 131 else { 132 //確認したのち結局モーダルビューを閉じる 133 let alertController = UIAlertController(title: "エラー", message: "画像を保存できませんでした", preferredStyle: .actionSheet) 134 let confirmAction = UIAlertAction(title: "確認", style: .cancel, handler: nil) 135 alertController.addAction(confirmAction) 136 dismiss(animated: true, completion: nil) 137 } 138 } 139 140 141}

イメージ説明

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

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

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

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

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

MasakiHori

2020/03/31 08:47

クラッシュした時に右下のコンソールに詳細なエラーが出力されます そのエラーを可能な限りすべて追記してください
hoshi-takanori

2020/03/31 12:00

適当なプロジェクトにそのコードを貼って実機で動かしてみたら動きましたよ。原因は別のところにあるのでは。Xcode の右下には AutoLayout の警告以外のエラーメッセージはありませんか?
PINE1103

2020/04/01 13:56

2020-04-01 22:49:47.921868+0900 scheduleApplication[37675:1236757] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "<NSLayoutConstraint:0x283b53ed0 UIView:0x103b062f0.width == - 16 (active)>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x283b53ed0 UIView:0x103b062f0.width == - 16 (active)> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. (lldb) が全てのエラー内容です。原因があるとしたらどのあたりが怪しいのか分かるでしょうか?
PINE1103

2020/04/02 03:29

最新に更新すると直りました!! ありがとうございました!!
guest

回答2

0

たぶん、「Privacy - Photo Library Usage Description」の設定を行なっていないのではないでしょうか。
行なっていなければ、フォトライブラリーにアクセスした瞬間に落ちるようになっています。

エラーメッセージにもInfo.plistの設定を行いなさいという表示が出ているはずです。

上記のリンクを参考に、Info.plistを設定すれば落ちないようになるはずです。

投稿2020/03/31 06:06

TsukubaDepot

総合スコア5086

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

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

PINE1103

2020/03/31 08:04

回答ありがとうございます! その設定はしております。上にInfo.plistのスクリーンショットを貼りましたのでみていただきたいです。
TsukubaDepot

2020/03/31 08:26

なるほど... 以前拝見した時のソースを参考に実機で動かすと、Info.plistに必要な項目を設定していない場合に上記の部分で落ちたのでそれかと思いましたが、違うのかもしれませんね。
PINE1103

2020/04/02 03:30

XcodeとiOSを最新のバージョンにすることで直りました! ありがとうございました!!
TsukubaDepot

2020/04/02 04:33

解決したようでよかったです。 何が原因か根本的な理由はわからないかもしれませんが、作者にbug reportを送っておくといいかもしれませんね。
PINE1103

2020/04/03 02:36

すいません、作者とはいったい誰のことでしょうか?
PINE1103

2020/04/03 13:21

なるほど。わかりました!ありがとうございます!
guest

0

自己解決

XcodeとiOSを最新のバージョンにする。

投稿2020/04/02 03:33

PINE1103

総合スコア20

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問