我正在尝试在我的应用程序中以编程方式打开应用程序商店应用程序。
我想做的是,我正在调用一项服务来检查当前的应用程序版本,如果需要更新,我应该打开应用程序商店应用程序,让用户更新我的应用程序。
注意:该应用程序尚未发布到商店,我仍处于编码阶段。
我尝试在 ViewDidLoad 方法中使用以下代码,但它不起作用(什么也没发生):
var nsurl = new NSUrl("itms://itunes.apple.com");
UIApplication.SharedApplication.OpenUrl(nsurl);
直接链接通过itms:
仅适用于实际设备,如果您在模拟器上测试,请使用https://itunes.apple.com/us/genre/ios/id36?mt=8
反而。
我建议使用itms://
实际设备上的链接,因为它可以防止用户在使用时看到的重定向https://
打开 iTunes 的链接。
bool isSimulator = Runtime.Arch == Arch.SIMULATOR;
NSUrl itunesLink;
if (isSimulator)
{
itunesLink = new NSUrl("https://itunes.apple.com/us/genre/ios/id36?mt=8");
}
else
{
itunesLink = new NSUrl("itms://itunes.apple.com");
}
UIApplication.SharedApplication.OpenUrl(itunesLink, new NSDictionary() { }, null);
您可能不想在设备上打开外部应用商店应用程序,而是考虑使用SKStoreProductViewController
:
bool isSimulator = Runtime.Arch == Arch.SIMULATOR;
if (!isSimulator)
{
var storeViewController = new SKStoreProductViewController();
storeViewController.Delegate = this;
var id = SKStoreProductParameterKey.ITunesItemIdentifier;
var productDictionaryKeys = new NSDictionary("SKStoreProductParameterITunesItemIdentifier", 123456789);
var parameters = new StoreProductParameters(productDictionaryKeys);
storeViewController.LoadProduct(parameters, (bool loaded, NSError error) =>
{
if ((error == null) && loaded)
{
this.PresentViewController(storeViewController, true, () =>
{
Console.WriteLine("SKStoreProductViewController Completed");
});
}
if (error != null)
{
throw new NSErrorException(error);
}
});
}
else
{
var itunesLink = new NSUrl("https://itunes.apple.com/us/genre/ios/id36?mt=8");
UIApplication.SharedApplication.OpenUrl(itunesLink, new NSDictionary() { }, null);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)