Created
April 5, 2012 04:36
-
-
Save yaakaito/2307976 to your computer and use it in GitHub Desktop.
gist: 2296450 の続き、文字列マッチだるいのでローカルファイル読み込んでUIWebViewからjs経由で教えてもらう -> 読み込む必要すらなかった
This file contains 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
#import <Foundation/Foundation.h> | |
@interface UserAgent : NSObject<UIWebViewDelegate> | |
@property BOOL loaded; | |
+ (NSString *)defaultUserAgent; | |
@end |
This file contains 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
#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