0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【iPad】UIActivityViewControllerで共有時にクラッシュする

Posted at

現象

iPad端末でのみUIActivityViewControllerで共有画面を表示させようとするとクラッシュする。
iPhoneでは発生せず、OSバージョン関係なくiPadのみで発生。

原因

元のコード
以下がiPhoneでのみUIActivityViewControllerが表示できていたコードです。

// インスタンス化
let activityVc = UIActivityViewController(activityItems: items, applicationActivities: nil)
    
// 表示
 self.present(activityVc, animated: true, completion: nil)

修正コード
以下のように表示対象を指定してあげる必要があるみたいでした。
iPhoneはデフォルトの設定で下からニュッとUIActivityViewControllerが出てきますが、iPadではデフォルトの設定がなく、指定をしないとどのViewに対してUIActivityViewControllerを出せば良いのか分からなくなるのが原因みたいでした。


// インスタンス化
let activityVc = UIActivityViewController(activityItems: items, applicationActivities: nil)

// 表示対象を指定
activityVc.popoverPresentationController?.sourceView = self.view

// 表示
 self.present(activityVc, animated: true, completion: nil)

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?