简体   繁体   中英

App crashes for share button on iPad

I've created an app where you can share your score. It works great on the iPhones, but on the iPads it crashes the app. I keep getting a "Thread 1: signal SIGABRT" in the AppDelegate.

class GameViewController: UIViewController, GameSceneDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        if let skView = self.view as? SKView {
            if skView.scene == nil{

                // create the scene

                let scene = GameScene(size: CGSize(width: 2048, height: 1536), delegate: self, gameState: .MainMenu)
                skView.showsFPS = false
                skView.showsNodeCount = false
                skView.ignoresSiblingOrder = true

                scene.scaleMode = .AspectFill

                skView.presentScene(scene)

            }
        }
        self.canDisplayBannerAds = true


    }
    override func prefersStatusBarHidden() -> Bool {
        return true
    }

    func screenshot() -> UIImage {


        UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 1.0)
        view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image


    }

    func shareString(string: String, url: NSURL, image: UIImage) {
        let vc = UIActivityViewController(activityItems: [string, url, image], applicationActivities: nil)
        presentViewController(vc, animated: true, completion: nil)
    }
}

Please attach this code with your exsiting func shareString

if youractivityView.respondsToSelector("popoverPresentationController") {
        youractivityView.popoverPresentationController.sourceView = parentView
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM