preface

A bug was found in 3.5.2 after the launch. Before the launch, our iOS junior brother accidentally changed part of the code, resulting in the dirty data being cached, and the project crashing when the cache was retrieved… (Apple’s audit is getting less serious…. Ok, I’m done writing this blog on my knees)..

Back to business:

There are many different hotfixes available in iOS, but I won’t cover them all here

Here’s an article about hotfixes in nuggets: A summary of the HotFix solution in iOS

The hot fix I chose is JSPatch. I think the advantages of JSPatch are:

  • noninvasive
  • The load on the
  • Relevant services mature

In the code

Big god can see the main point, if it is the same dish as me chicken can follow the blog step by step, will succeed in making JSPatch run

Step 1: Create a Demo. Add a Label to the ViewController and declare a test method to assign a value to label.text

OC:

Swift:

To make it easier to drag the label directly into the StoryBoard (you can create it in code if you don’t like drag controls)

Adding dynamic to Swift for each variable and method ensures that Swift methods can be dynamically replaced.

Swift Runtime analysis: Still like OC Runtime?


Step 2: Open the JSPatch website to download the SDK:jspatch.com/Index/sdk


Step 3: Project configuration (this step is a little more complicated)

Write the following code in the AppDelegate:

  • OC

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override Point for Customization after application launch. [JSPatch startWithAppKey:@" your AppKey"]; // Check the status of the callback, such as update or script execution, etc. JSPatch setupCallback:^(JPCallbackType type, NSDictionary *data, NSError *error) {}]; [JSPatch setupDevelopment]; [JSPatch sync]; return YES; }Copy the code
  • Swift

      func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
          // Override point for customization after application launch.
          JSPatch.startWithAppKey("你的Appkey")
          JSPatch.setupCallback { (type, data, error) in
              print(type)
              print(data)
          }
          JSPatch.setupDevelopment()
          JSPatch.sync()
          return true
      }Copy the code

At this stage, the project configuration is complete, and the next step is to start sending patches to the project


Step 4: Open the JSPatch website and click on the upper left corner to register ->www.jspatch.com/


Step 5: Create your App. You can write the name and AppID optionally


Step 6: Click Add APP version to create an APP version

Introduce the APP after creation:

  • AppKey is used later to activate JSPatch in your project
  • Add App Version is created according to the Version of your App (if the Version is not correct, the patch will not be downloaded)

Step 7: Create a main.js file and fill it with the following code:

  • OC

    DefineClass ('ViewController', {test: function() {self.label().settext ("label text changed "); defineClass('ViewController', {test: function() {self.label().settext ("label text changed "); }})Copy the code
  • Swift

    DefineClass (' HotFixDemo. ViewController '{test: the function () {self. The label (). The setText (" label text is changed "); }})Copy the code

Swift overrides methods and classes with project names, so the specification should be project names. Class name (method name) The project name is also used when registering a class

Step 8: Click on the 1.0 you just created, upload the saved JS to the JSPatch server,

Select the file and select the main.js file that you just created. (At least one main.js file is required when uploading the patch. If you need to upload multiple files, click the plus sign on the right.)

Be sure to check development Preview first so that the test is successful

When everything is done, select Submit

Run your project. If the command line displays the following, your project has been patched

Since patches are downloaded before they take effect, you won’t see them until the next time you run them

You can see that my code assigns label to AAAA and replaces label.text with JSPatch

If you have any problems, please leave a message to me, AND I will timely reply and update the blog

Some other information:

JSPatch document

IOS Hack: Getting rid of Bugs (JSPatch)

Objective-c code is converted to JavaScript

Possible potholes

  • Make sure the version on the JSPatch website is the same as the one in the project
  • Do not write the name of label wrong.. I could have written it under a different name
  • Swift must precede methods and properties with dynamic; Swift classes that do not inherit from NSObject cannot be dynamically replaced
  • Swift replaces classes and methods by adding the project name before the class/method name than OC does
  • If the project runs and console output does not find the document, there is a configuration error on the website
  • Js upload must be encrypted, must be encrypted, must be encrypted

Basic posture

Find bugs -> fix bugs in the project -> translate the modified and problematic classes and methods into JS and upload them to the website -> release patches

This time the Bug is really sorry for the master users, let me kneel until the urgent review completed, and the use of the hot repair technology to ensure that the future will not let you master encounter today’s situation…

Added on 27 August

JS must be encrypted, here is the method screenshots and documentation:

Encryption method:

Documents: jspatch.com/Docs/rsa