2012.09.20
iOS の UIWebView で UserAgent を変える簡単な方法とその落とし穴
iOS の UIWebView で UserAgent を変えるのって意外とややこしいという認識だったのですが、検索して調べてみたら簡単な方法がありました。
» [Easily set the User-Agent in a UIWebView \| MPHWeb](http://www.mphweb.com/en/blog/easily-set-user-agent-uiwebview)
で紹介されている方法で以下のたった三行で済みます。
これで十分だったのですが、思わぬ落とし穴が。。
UserAgent を変更したアプリに AdMob のバナーを貼っていたのですが、広告がまったく表示されなくなってしまいました。
上記方法だと、すべてのリクエストの UserAgent を変えてしまうことになり、どうも変更前の通常の UserAgent を送っていないと AdMob 側でバナーを表示しないようになっていたようです。
AdMob を使っている方はご注意を。。
というわけで、僕は上記方法を断念しましたが、UserAgent を単に変更したいだけならば使えると思います。
» [Easily set the User-Agent in a UIWebView \| MPHWeb](http://www.mphweb.com/en/blog/easily-set-user-agent-uiwebview)
で紹介されている方法で以下のたった三行で済みます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"custom user agent", @"UserAgent", nil]; | |
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary]; | |
[dictionary release]; |
これで十分だったのですが、思わぬ落とし穴が。。
UserAgent を変更したアプリに AdMob のバナーを貼っていたのですが、広告がまったく表示されなくなってしまいました。
上記方法だと、すべてのリクエストの UserAgent を変えてしまうことになり、どうも変更前の通常の UserAgent を送っていないと AdMob 側でバナーを表示しないようになっていたようです。
AdMob を使っている方はご注意を。。
というわけで、僕は上記方法を断念しましたが、UserAgent を単に変更したいだけならば使えると思います。
2012/09/20 05:02:39