下面是我修改之后的代码:
1. 在app内以子视图方式打开其他app预览,仅支持6.0以上
openAppWithIdentifier(appId: String)
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)2. 分享文字图片信息,ipad上会以sourceView为焦点弹出选择视图
share(textToShare: String, url: String, image: UIImage, sourceView: UIView)/// 在app内以子视图方式打开其他app预览,仅支持6.0以上 private func openAppWithIdentifier(appId: String) { if let _ = NSClassFromString("SKStoreProductViewController") { let storeProductViewController = SKStoreProductViewController() storeProductViewController.delegate = self let dict = NSDictionary(object:appId, forKey:SKStoreProductParameterITunesItemIdentifier) as! [String : AnyObject] storeProductViewController.loadProductWithParameters(dict, completionBlock: { (result, error) - Void in// self.presentViewController(storeProductViewController, animated: true, completion: nil) }) self.presentViewController(storeProductViewController, animated: true, completion: nil) }else { UIApplication.sharedApplication().openURL(NSURL(string: "itms-apps://itunes.apple.com/app/id(appId)")!) } } /// 分享文字图片信息,ipad上会以sourceView为焦点弹出选择视图 private func share(textToShare: String, url: String, image: UIImage, sourceView: UIView) { let objectsToShare = [textToShare, url, image] let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil) if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone { self.presentViewController(activityViewController, animated: true, completion: nil) }else { let popover = activityViewController.popoverPresentationController if (popover != nil){ popover?.sourceView = sourceView popover?.sourceRect = sourceView.frame popover?.permittedArrowDirections = UIPopoverArrowDirection.Any self.presentViewController(activityViewController, animated: true, completion: nil) } } }