Hot fix Iosapp with Jspatch platform

Source: Internet
Author: User

iOS product development often encounter this situation, the online discovery of a serious bug, may be a crash, may be a function can not be used, then can do is to quickly fix the bug and then submit to wait for a lengthy audit, even if the application expedited will not go there, even if the audit is finished, Also look forward to the user to upgrade quickly, the user does not upgrade or the same vulnerability, this situation allows developers to pay a large cost to complete the bug fix.

Jspath is to solve this problem, only need to introduce the smallest Jspatch engine in the project, you can also call Objective-c native API in JavaScript language, update the app dynamically, fix the bug.

Jspaht itself is an open source project, Project address: Http://jspatch.com/,github Address: Https://github.com/bang590/JSPatch
An example is given on his website:

1 @implementationJptableviewcontroller2 ...3- (void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath4 {5NSString *content = Self.datasource[[indexpath Row]];//may exceed array range resulting in crash6Jpviewcontroller *ctrl =[[Jpviewcontroller alloc] initwithcontent:content];7 [Self.navigationcontroller Pushviewcontroller:ctrl];8 }9 ...Ten @end

This bug can be fixed by issuing the following JavaScript code:

1 //JS2DefineClass ("Jptableviewcontroller", {3   //instance method definitions4 tableview_didselectrowatindexpath:function (TableView, Indexpath) {5var row =Indexpath.row ()6     if(Self.datasource (). length > Row) {//plus the logic of judging the bounds.7var content =Self.dataarr () [row];8var ctrl =Jpviewcontroller.alloc (). initwithcontent (content);9 Self.navigationcontroller (). Pushviewcontroller (ctrl);Ten     } One   } A}, {})

Jsptch requires a backend service to distribute and manage scripts, and to handle transport security.

Register to get Appkey

Register an account on the platform and create a new app to get the corresponding appkey.

Import the SDK into the project

SDK Address: HTTP://JSPATCH.COM/INDEX/SDK
The current download of the SDK version name is: JSPatch 2.framework , you need to remove the middle of the space, or import items will be error.
Select when importing the project Copy items if needed .
You also need to add the dependencies for the framework JavaScriptCore.framework and libz.tbd .

Add Jspatch Code

To add code in APPDELEGATE.M:

1 #import "AppDelegate.h"2 #import<JSPatch/JSPatch.h>3 4 @implementationappdelegate5 6-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {7[Jspatch Startwithappkey:@"F78378d77e5783e8"];8 [Jspatch sync];9     returnYES;Ten } One @end
Upload JS repair files in the platform

For simplicity we only upload a simple UIAlertView , pop up a prompt box:

 1  ar alertview = require ( " uialertview   " ). Alloc (). Init ();  2  alertview.settitle ( " alert   " );  3  alertview.setmessage ( " alertview from JS   " );  4  alertview.addbuttonwithtitle ( ok   " );  5  alertview.show (); 

Uialertview was instantiated with JavaScript, and the file name needs to be named main.js .

From server to client

Upload to the main.js server, issued to version 1.0 of the client above.
An error occurred while requesting the service to load the script:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
The reason for this error is that iOS9 introduces a new feature App Transport Security(ATS) , which simply means that the request inside the app must use the HTTPS protocol.
It is obvious that the URL here does not use HTTPS, and we can avoid this problem by setting it up first:

1.在info.plist中添加NSAppTransportSecurity类型为Dictionary.2.在NSAppTransportSecurity中添加NSAllowsArbitraryLoads类型为Boolean,值为YES

Operating effect:

Hot fix Iosapp with Jspatch platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.