Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
11
Help us understand the problem. What is going on with this article?
@unsoluble_sugar

iPadでUIActivityViewControllerを呼ぶとクラッシュする現象の対応

More than 3 years have passed since last update.

iPadでUIActivityViewControllerがクラッシュする

iOSアプリでUIActivityViewController(OS標準の共有機能)を呼ぶ際に、iPadのみでクラッシュする現象に遭遇。
2017-10-06 18.33.20.png
エラーメッセージは以下のとおり。

Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIActivityViewController (). In its current trait environment, the modalPresentationStyle of a UIActivityViewController with this style is UIModalPresentationPopover. You must provide location information for this popover through the view controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the view controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'

対処法

iPadの場合はsourceViewsourceRectを指定する必要がある。

UIActivityViewController *activityViewController = [[[UIActivityViewController alloc] initWithActivityItems:actItems applicationActivities:nil] autorelease];
activityViewController.popoverPresentationController.sourceView = self.view;
activityViewController.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 1.0, 1.0);

上記コードでクラッシュが回避され、ど真ん中にUIActivityViewControllerが表示される。

11
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
unsoluble_sugar
フルオタクエンジニア。ロボティクスベンチャーでPMやってます。 最近はZennで技術記事書いてます。 https://zenn.dev/unsoluble_sugar
techhunterorg
Always absorb new technology

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
11
Help us understand the problem. What is going on with this article?