我有一个网站,显示iOS上使用HTML元标记的智能应用程序横幅。我只想在iPod上显示横幅广告。防止在iPad上显示智能应用程序横幅
如何防止它在iPad上显示?
我使用(从Apple资源)代码:
<meta name="apple-itunes-app" content="app-id=myAppStoreID">
我有一个网站,显示iOS上使用HTML元标记的智能应用程序横幅。我只想在iPod上显示横幅广告。防止在iPad上显示智能应用程序横幅
如何防止它在iPad上显示?
我使用(从Apple资源)代码:
<meta name="apple-itunes-app" content="app-id=myAppStoreID">
你必须使用Javascript来做到这一点,因为没有正确的方法来完成HTML中的平台检测。
摆脱HTML代码中的元标记,并使用下面的代码片段,或者只是使用它的一部分,然而你喜欢。如果您想“按原样”使用它,请将其粘贴在身体的底部。
(function($){
var is_iPad = navigator.userAgent.match(/iPad/i) != null;
// Fill in your Apple-App stuff here
var app_id = "<YOUR_APPLE_APP_ID>",
affiliate_data = null,
app_argument = null;
// exclude iPad
if(!is_iPad) {
var meta = $("<meta>"), content = 'app-id=' + app_id;
meta.attr('name', 'apple-itunes-app');
// Optional stuff (only when filled in)
if(affiliate_data) content += ', affiliate-data=' + affiliate_data;
if(app_argument) content += ', app-argument=' + app_argument;
// Apply
meta.attr('content', content);
$('head').append(meta);
}
}(jQuery));
写这个方法来知道在哪个设备上的程序正在运行
// in .h file
+ (BOOL) isIdiomIsIPad;
// in .m file
+ (BOOL) isIdiomIsIPad
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
return YES;
else
return NO;
}
然后您正在应用您的自定义的方法使用此
if([[Global isDeviceType] isEqualToString:iPad])
{
//do what you want
// Global is class name where method was defined, write your class name in which you define that method and import it where you are wiring this code
}
我很抱歉,但我觉得我还不够清楚:这是一个网站,而不是一个本地应用程序。因此我的标签和参考苹果资源。 –
oops。对不起,这是我的错误,我读得很好 – iAhmed
虽然我用了一个稍微不同的实现,但这确实是解决方案。他们的方式我尝试了它有点不对。 –
虽然这确实会添加适当的标签,但Safari for iPad没有选择标签并显示横幅。我在iOS 6和iOS 7设备上进行了测试。 – Christian