[英]Prevent Smart app banner from showing on iPad
我有一個網站,該網站使用HTML meta標簽在iOS上顯示智能應用橫幅。 我只希望橫幅廣告顯示在iPhone和iPod上。
如何防止它出現在iPad上?
蘋果資源: http : //developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html
我正在使用的代碼(來自Apple資源):
<meta name="apple-itunes-app" content="app-id=myAppStoreID">
您必須使用Javascript來執行此操作,因為沒有適當的方法來僅使用HTML進行平台檢測。
擺脫HTML代碼中的meta標記,並使用以下代碼段,或僅使用其中的一部分,即可使用。 如果您想按原樣使用它,請將其粘貼在主體底部。
(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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.