您的位置:首页 > 移动开发 > IOS开发

iOS Tips

2015-12-09 13:45 537 查看
1. LLDB调试打印

(lldb) p UIScreen.mainScreen.bounds
error: property 'bounds' not found on object of type 'id'
error: 1 errors parsing expression
(lldb) expr @import UIKit
(lldb) p UIScreen.mainScreen.bounds
(CGRect) $1 = (origin = (x = 0, y = 0), size = (width = 414, height = 736))
(lldb)


2.UIWebView设置UA

@implementation lzxzWebViewUtility : NSObject

+ (id)uiWebDocumentView:(UIWebView *)webview
{
NSString *str = @"_documentView";
id documentView = [webview performSelector:NSSelectorFromString(str)];
id coreWebView = [documentView performSelector :@selector(webView)];
return coreWebView;
}

+(NSString *)langzuxiaoziUA:(UIWebView *)webview
{
static NSString* lbUA=nil;

NSString*  appUA=objc_msgSend([lzxzWebViewUtility uiWebDocumentView:webview], NSSelectorFromString(@"applicationNameForUserAgent"));

if(lbUA == nil){
lbUA=[[appUA stringByAppendingFormat:@" langzuxiaozi/%@",[lzxzUIGlobal appBuildNum]] retain];
}
return lbUA;
}

+ (void)changeWebview:(UIWebView *)webview UserAgent:(NSString*)strUA
{
SEL sel = NSSelectorFromString(@"setApplicationNameForUserAgent:");

[[lzxzWebViewUtility uiWebDocumentView:webview] performSelector:sel withObject:strUA];
}

@end

//获取到带langzuxiaozi字符的ua
NSString* strUA = [lzxzWebViewUtility langzuxiaoziUA:self.webView];
//设置webview自定义ua
[lzxzWebViewUtility changeWebview:self.webView UserAgent:strUA];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: