{"id":1758,"date":"2017-08-10T15:00:30","date_gmt":"2017-08-10T07:00:30","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=1758"},"modified":"2017-08-10T15:00:30","modified_gmt":"2017-08-10T07:00:30","slug":"ios%e5%af%b9%e6%8e%a5hybrid%e6%a1%86%e6%9e%b6vassonic%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=1758","title":{"rendered":"iOS\u5bf9\u63a5Hybrid\u6846\u67b6VasSonic\u6559\u7a0b"},"content":{"rendered":"<p>\n\t\u817e\u8baf\u5f00\u6e90\u7684 Hybrid \u6846\u67b6 VasSonic \u8fd9\u4e24\u5929\u88ab\u63a8\u51fa\u6765\u4e86\uff0c\u4eca\u5929<a href=\"https:\/\/www.zhihu.com\/question\/63622287\" name=\"\u5982\u4f55\u8bc4\u4ef7\u817e\u8baf\u5f00\u6e90\u7684 Hybrid \u6846\u67b6 VasSonic?\" target=\"_blank\" title=\"\u5982\u4f55\u8bc4\u4ef7\u817e\u8baf\u5f00\u6e90\u7684 Hybrid \u6846\u67b6 VasSonic?\">\u77e5\u4e4e<\/a>\u4e0a\u4e5f\u662f\u70ed\u8bc4\u5982\u6f6e\u3002\u4e0a\u9762\u8be6\u7ec6\u7684\u8bf4\u660e\u4e86 VasSonic \u7684\u53d1\u5c55\u53f2\u3002\n<\/p>\n<p>\n\t\u4ece\u76ee\u524d\u6765\u770b\uff0c\u4ee5\u540e\u5fae\u4fe1\u7684\u5c0f\u7a0b\u5e8f\u6253\u5f00\u901f\u5ea6\u5c06\u66f4\u5feb\u4e86\u3002\u4e0b\u9762\u8bf4\u8bf4VasSonic\u7684\u4e3b\u8981\u539f\u7406\u3002\n<\/p>\n<h2>\n\tVasSonic\u7684\u4e3b\u8981\u539f\u7406<br \/>\n<\/h2>\n<p>\n\tVasSonic\u5728\u5185\u5bb9\u8bf7\u6c42\u65b9\u9762\u7528\u4e86\u4e09\u62db\uff1a\n<\/p>\n<ol>\n<li>\n\t\t\u52a8\u6001\u7f13\u5b58\n\t<\/li>\n<li>\n\t\t\u589e\u91cf\u66f4\u65b0\n\t<\/li>\n<li>\n\t\t\u5e76\u884c\u52a0\u8f7d\n\t<\/li>\n<\/ol>\n<p>\n\t\u901a\u8fc7\u5bf9HTML\u5185\u5bb9\u6dfb\u52a0\u6ce8\u91ca\u6765\u5b9a\u4e49\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u683c\u5f0f\uff0c\u5bf9HTML\u6587\u6863\u8fdb\u884c\u5206\u5757\u3002\n<\/p>\n<ul>\n<li>\n\t\t\u52a8\u6001\u7f13\u5b58\uff1a\u6307\u5728\u9875\u9762\u8303\u56f4\u5185\uff0c\u5bf9\u5206\u5757\u540e\u7684\u540c\u5bb9\u8fdb\u884c\u66f4\u7ec6\u5316(\u5168\u5c40\u3001\u5c40\u90e8)\u7684\u7f13\u5b58\u3002\n\t<\/li>\n<li>\n\t\t\u589e\u91cf\u66f4\u65b0\uff1a\u6709\u7f13\u5b58\u7684\u60c5\u51b5\u4e0b\uff0c\u53ea\u5bf9\u5206\u5757\u540e\u7684\u5c40\u90e8\u5185\u5bb9\u8fdb\u884c\u589e\u91cf\u66f4\u65b0\u3002\n\t<\/li>\n<li>\n\t\t\u5e76\u884c\u52a0\u8f7d\uff1aVasSonic\u4f7f\u7528\u7ec8\u7aef\u5e94\u7528\u5c42\u539f\u751f\u4f20\u8f93\u901a\u9053\u53d6\u4ee3\u7cfb\u7edf\u6d4f\u89c8\u5668\u5185\u6838\u81ea\u8eab\u8d44\u6e90\u4f20\u8f93\u901a\u9053\u6765\u8bf7\u6c42\u9875\u9762\u4e3b\u8d44\u6e90\u3002\u5c31\u662f\u901a\u8fc7VasSonic\u5728\uff37ebView\u521d\u59cb\u5316\u8fc7\u7a0b\u4e2d\u65f6\uff0c\u540c\u6b65\u5e76\u884c\u4ece\u670d\u52a1\u5668\u52a0\u8f7d\u9875\u9762\uff0c\u800c\u4e0d\u662fwebview\u521d\u59cb\u5316\u540e\u518d\u53bb\u8bf7\u6c42\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t\u4e0b\u9762\u56de\u5230\u4eca\u5929\u7684\u4e3b\u9898\u3002iOS\u5bf9\u63a5Hybrid\u6846\u67b6VasSonic\u6559\u7a0b\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"vas Sonic\" src=\"http:\/\/ocuzluml6.bkt.clouddn.com\/Vas-Sonic.png\" style=\"width: 428px;height: 120px\" \/>\n<\/p>\n<h2>\n\tiOS\u4f7f\u7528<br \/>\n<\/h2>\n<p>\n\t\u6b65\u9aa41\uff1a\u5bfc\u5165\u5e76\u58f0\u660e\n<\/p>\n<p>\n\t\u6784\u5efa\u58f0\u6ce2\u6846\u67b6 \u5c06Sonic.framework\u6dfb\u52a0\u5230\u4e3b\u9879\u76ee\u4e2d\u7684\u4f9d\u8d56\u9879\u3002\u7136\u540e@import Sonic\u6ce8\u518cSonicURLProtocol\uff1a\n<\/p>\n<pre class=\"brush:plain;\">\r\n[NSURLProtocol registerClass:[SonicURLProtocol class]];\r\n\r\n@interface SonicWebViewController : UIViewController&lt;SonicSessionDelegate,UIWebViewDelegate&gt;<\/pre>\n<p>\n\t\u6b65\u9aa42\uff1a\u5b9e\u65bd SonicSessionDelegate\n<\/p>\n<pre class=\"brush:plain;\">\r\n#pragma mark - Sonic Session Delegate\r\n\/*\r\n * \u8c03\u7528\u56de\u6765\u65f6\uff0c\u58f0\u6ce2\u4f1a\u53d1\u9001\u8bf7\u6c42\u3002\r\n *\/\r\n- (void)sessionWillRequest:(SonicSession *)session\r\n{\r\n    \/\/This callback can be used to set some information, such as cookie and UA.\r\n}\r\n\/*\r\n *\u5f53Sonic\u8981\u6c42WebView\u91cd\u65b0\u52a0\u8f7d\u65f6\u56de\u8c03\uff0c\u4f8b\u5982\u6a21\u677f\u66f4\u6539\u6216\u53d1\u751f\u9519\u8bef\u3002 \r\n *\/\r\n- (void)session:(SonicSession *)session requireWebViewReload:(NSURLRequest *)request\r\n{\r\n    [self.webView loadRequest:request];\r\n}<\/pre>\n<p>\n\t\u6b65\u9aa43\uff1a\u5728WebView ViewController\u4e2d\u4f7f\u7528Sonic\n<\/p>\n<pre class=\"brush:plain;\">\r\n- (instancetype)initWithUrl:(NSString *)aUrl\r\n{\r\n    if (self = [super init]) {\r\n        \r\n        self.url = aUrl;\r\n        \r\n        \/\/\u7528URL\u521b\u5efa\u4e00\u4e2a\u58f0\u97f3\u4f1a\u8bdd\u3002\r\n        [[SonicClient sharedClient] createSessionWithUrl:self.url withWebDelegate:self];\r\n    }\r\n    return self;\r\n}\r\n\/*\r\n * \u5728WebView\u521d\u59cb\u5316\u540e\u7acb\u5373\u53d1\u9001Sonic\u5c5e\u6027\u7684\u8bf7\u6c42\u3002\r\n *\/\r\n- (void)loadView\r\n{\r\n    [super loadView];\r\n    \r\n    self.webView = [[UIWebView alloc]initWithFrame:self.view.bounds];\r\n    self.webView.delegate = self;\r\n    self.view = self.webView;\r\n    \r\n    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.url]];\r\n    \r\n    \/*\r\n     * \u5982\u679cSonicSession\u4e0d\u4e3a\u7a7a\uff0cSonic\u4f7f\u7528\u81ea\u5b9a\u4e49SonicWebRequest\u800c\u4e0d\u662f\u539f\u59cb\u7f51\u7edc\u8bf7\u6c42\u3002 \r\n     *\/\r\n    if ([[SonicClient sharedClient] sessionWithWebDelegate:self]) {\r\n        [self.webView loadRequest:sonicWebRequest(request)];\r\n    }else{\r\n        [self.webView loadRequest:request];\r\n    }\r\n}<\/pre>\n<p>\n\t\u6b65\u9aa44\uff1a\u901a\u8fc7JavaScript\u56de\u8c03\u4e0e\u7f51\u7ad9\u4ea4\u4e92\u3002\n<\/p>\n<pre class=\"brush:plain;\">\r\n- (void)getDiffData:(NSDictionary *)option withCallBack:(JSValue *)jscallback\r\n{\r\n    \/*\r\n     * ViewController\u53d1\u9001Sonic\u8bf7\u6c42\u5e76\u901a\u8fc7\u56de\u8c03\u8fd4\u56de\u7ed3\u679c\u3002 \r\n     *\/\r\n    [[SonicClient sharedClient] sonicUpdateDiffDataByWebDelegate:self.owner completion:^(NSDictionary *result) {\r\n       \r\n        \/*\r\n         * \u8fd4\u56de\u7ed3\u679c\u3002\r\n         *\/\r\n        NSData *json = [NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingPrettyPrinted error:nil];\r\n        NSString *jsonStr = [[NSString alloc]initWithData:json encoding:NSUTF8StringEncoding];\r\n        \r\n        JSValue *callback = self.owner.jscontext.globalObject;\r\n        [callback invokeMethod:@\"getDiffDataCallback\" withArguments:@[jsonStr]];\r\n        \r\n    }];\r\n}<\/pre>\n<p>\n\t\u6b65\u9aa45\uff1a\u5220\u9664\u58f0\u97f3\u4f1a\u8bdd\u3002\n<\/p>\n<pre class=\"brush:plain;\">\r\n- \uff08void\uff09dealloc\r\n{\r\n[[SonicClient sharedClient ] removeSessionWithWebDelegate\uff1aself ];\r\n}<\/pre>\n<p>\n\tOK\uff0c\u7ecf\u8fc7\u4e0a\u97625\u4e2a\u6b65\u9aa4\uff0c\u4e00\u4e2a\u5b8c\u6574\u7684IOS\u5b9e\u4f8b\u5c31\u5b8c\u6210\u4e86\u3002\u8d76\u7d27\u8bd5\u8bd5\u5427\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=1758\">iOS\u5bf9\u63a5Hybrid\u6846\u67b6VasSonic\u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u817e\u8baf\u5f00\u6e90\u7684 Hybrid \u6846\u67b6 VasSonic \u8fd9\u4e24\u5929\u88ab\u63a8\u51fa\u6765\u4e86\uff0c\u4eca\u5929\u77e5\u4e4e\u4e0a\u4e5f\u662f\u70ed\u8bc4\u5982\u6f6e\u3002\u4e0a\u9762\u8be6\u7ec6\u7684\u8bf4\u660e\u4e86  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118],"tags":[1421,1422,1418,1420],"class_list":["post-1758","post","type-post","status-publish","format-standard","hentry","category-ndisdevelop","tag-hybrid","tag-ios","tag-sonic","tag-vassonic"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1758","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1758"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1758\/revisions"}],"predecessor-version":[{"id":1759,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1758\/revisions\/1759"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}