xamarin ios 10 在我的应用程序中以编程方式打开应用程序商店应用程序 [英] xamarin ios 10 open app store application programmatically in my app
问题描述
我正在尝试在我的应用中以编程方式打开应用商店应用.
i'm trying to open app store application programmatically in my app.
我想做的是调用一个服务来检查当前的应用程序版本,如果它需要更新,我应该打开应用程序商店应用程序让用户更新我的应用程序.
what i'm trying to do is that i'm calling a service to check at the current app version and if it needs update i should open app store application to let the user update the my app.
注意:应用尚未发布到商店,我仍处于编码阶段.
我尝试在 ViewDidLoad 方法中使用以下代码,但它不起作用(什么也没发生):
i tried to use the following code in ViewDidLoad method, but it's not working (nothing happened):
var nsurl = new NSUrl("itms://itunes.apple.com");
UIApplication.SharedApplication.OpenUrl(nsurl);
推荐答案
通过 itms:
的直接链接仅适用于实际设备,如果您在模拟器上进行测试,请使用 https://itunes.apple.com/us/genre/ios/id36?mt=8
代替.
A direct link via itms:
will only work in an actual device, if you are testing on a simulator, use https://itunes.apple.com/us/genre/ios/id36?mt=8
instead.
我建议在实际设备上使用 itms://
链接,因为它可以防止用户在使用 https://
链接打开 iTunes 时看到的重定向.
I would recommend using itms://
link on the actual device as it prevents the redirects that user sees when using a https://
link to open 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
将用户留在您的应用程序中,而不是在设备上打开外部应用商店应用程序:
Instead of opening the external Store app on the device, you might want to consider keeping the user inside of your app by using a 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);
}
这篇关于xamarin ios 10 在我的应用程序中以编程方式打开应用程序商店应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!