Skip to content

Instantly share code, notes, and snippets.

@yaakaito
Created April 5, 2012 04:36
Show Gist options
  • Save yaakaito/2307976 to your computer and use it in GitHub Desktop.
Save yaakaito/2307976 to your computer and use it in GitHub Desktop.
gist: 2296450 の続き、文字列マッチだるいのでローカルファイル読み込んでUIWebViewからjs経由で教えてもらう -> 読み込む必要すらなかった
#import <Foundation/Foundation.h>
@interface UserAgent : NSObject<UIWebViewDelegate>
@property BOOL loaded;
+ (NSString *)defaultUserAgent;
@end
#import "UserAgent.h"
@implementation UserAgent
@synthesize loaded;
+ (NSString *)defaultUserAgent {
// shared
static dispatch_once_t pred = 0;
static NSString *applicationUserAgent;
dispatch_once(&pred, ^{
UserAgent *userAgent = [[self alloc] init];
UIWebView *webView = [[UIWebView alloc] init];
NSString *command =[NSString stringWithFormat:@"navigator.userAgent"];
applicationUserAgent = [webView stringByEvaluatingJavaScriptFromString:command];
[applicationUserAgent retain];
[webView release];
[userAgent release];
});
return applicationUserAgent;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
self.loaded = YES;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment