2015-07-19 2 views
0

Я пытаюсь добавить кнопку, чтобы поделиться некоторыми предложениями в Twitter, Facebook ... и т. Д. Все это работает на всех моделях iPhone, но симулятор падает с iPad.Кнопка совместного доступа отлично работает на iPhone, но падает на iPad.

Это мой код:

@IBAction функ shareButton (отправитель: AnyObject) {

frase = labelFrases.text! 
    autor = labelAutores.text! 


    var myShare = "\(frase) - \(autor)" 

    let activityVC: UIActivityViewController = UIActivityViewController(activityItems: [myShare], applicationActivities: nil) 



    self.presentViewController(activityVC, animated: true, completion: nil) 

И это ошибка:

Нагрузочное приложение из-за неперехваченное исключение 'NSGenericException', Причина: 'UIPopoverPresentationController (< _UIAlertControllerActionSheetRegularPresentationController: 0x7c0f9190>) должен иметь не-nil sourceView или barButtonItem, установленный до возникновения презентации

Как его решить? Благодаря

ответ

1

для Ipad (IOS> 8,0), вам необходимо установить popoverPresentationController:

//check ipad 
    if (UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad) 
    { 
     //ios > 8.0 
     if (activityVC.respondsToSelector(Selector("popoverPresentationController"))) { 
      activityVC.popoverPresentationController?.sourceView = super.view 
     } 
    } 

    self.presentViewController(activityVC, animated: true, completion: nil) 

Более подробная информация здесь: UIActivityViewController crashing on iOS8 iPads

Смежные вопросы