gpt4 book ai didi

ios - 通过 ActivityViewController iOS swift 共享应用程序链接?

转载 作者:搜寻专家 更新时间:2023-10-31 22:13:56 26 4
gpt4 key购买 nike

我的应用尚未上线。我从 App Store Connect 获得了应用 ID。我想在社交媒体应用程序上分享应用程序链接。我使用了 UIActivityViewController:

let string1 = "itms-apps://itunes.apple.com/app/idXXXXXXX"
let url = NSURL(string: string1)

let shareItems = [UIApplication.sharedApplication().openURL(url!)]

let activityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: nil)

问题:它没有显示 WhatsApp 等社交媒体应用。

enter image description here

最佳答案

Swift 4 或更高版本的解决方案:

此解决方案也适用于 iPad(上述解决方案在 iPad 上崩溃):

if let urlStr = NSURL(string: "https://apps.apple.com/us/app/idxxxxxxxx?ls=1&mt=8") {
let objectsToShare = [urlStr]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

if UIDevice.current.userInterfaceIdiom == .pad {
if let popup = activityVC.popoverPresentationController {
popup.sourceView = self.view
popup.sourceRect = CGRect(x: self.view.frame.size.width / 2, y: self.view.frame.size.height / 4, width: 0, height: 0)
}
}

self.present(activityVC, animated: true, completion: nil)
}

关于ios - 通过 ActivityViewController iOS swift 共享应用程序链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35861962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com