IOS Dynamic Update

Source: Internet
Author: User

IOS Dynamic UpdateAppDynamic Update
  • 1, the control to window the hierarchical relationship:
  • 2. Detailed path of the analysis control:
  • 3. Dynamic modification of controls:
  • 4. Tool article:
Hierarchical relationship of Views:

Each App , at least one root Window , usually we only use one. windowThere is one rootViewController , this is what we call the root view, all of our controllers are placed rootViewController inside.

This is the simplest hierarchical relationship.

If there is such a path in the project, what can we do?

  • When the project is complex, you can modify the state of the control directly elsewhere
  • When a control is named and does not appear, you can use a path to help find
  • By the server issued some configuration, using Runtime to dynamically modify the project has been launched

Here's how to use code to find the path to these views (controls)

Analyze the detailed path of the control 1, find the rootWindow:

Each view, control, and their final root is returned by the main function application , which [UIApplication sharedApplication] can be obtained. applicationis windows a property of an array, which contains all of this application Window , and we usually use the first oneapplication.windows[0]

2. Traverse the View:

Got the window object everything is well done. And then window get rootViewController , in the acquisition of rootViewController all the childViewControllers and inside view subviews , has been recursive to get the current screen all the view objects, but also by runtime property delegate the Take it out.
Combined Reveal or Xcode self-bringing Captuer View Hiearachy , we can speculate on the implementation of these two principles:
1. Get root view based on application
2, recursively get all the controls inside
3, according to their hierarchical relationship, a layer of painting out

Dynamically modifying controls

1. Upload the details of all the controls obtained above to the server.
2, according to the business needs by the server to send us a corresponding configuration list, button as an example: the Configuration column table must have:

1), button full path: If UIWindow UIWindow UIView UIView UILayoutContainerView UITabBar UIViewUIButton
2), button Unique identification: A tag Unique identifier generated by a value or a set of algorithms that you implement to prevent button mixing with views at the same level.
3), according to the path and unique identification to match App the control, matching and the above lookup principle is interlinked.
4), the matching successful representative button does exist, according to business needs to do follow-up operations.
Tip: Match the policy as much as possible to prevent an unexpected situation where a one or two identity generation fails or the build is the same.

3, button the state of the modification.

1), such as a button point will Crash or temporarily do not need to be clicked, but also show it, you can directly modify button the enabled properties.
2), such as a business temporarily closed, you can directly modify the entry 按钮 frame for 0, provided that the automatic layout has been done.
3), such as to 按钮 add monitoring events to purchaseaddTarget: action: forControlEvents:
targetcan also be obtained through the above 遍历视图 , action can be issued by the server, you can start to write dead, and so on when there is a need for direct transmission of different parameters on the line.

4, bound to find the control, the interface must have been initialized to complete the line, if the interface has not been generated must not find this control. Here are two ideas for you:

1, using runtime Method Swizzing , directly modify the control method and didMoveToSuperview didMoveToWindow dynamic binding, and so on after the control is loaded and then go to modify, find the correct path is sure to find.
2, in the specific class, such as the initialization method of the control after the call, then to perform dynamic modification, such as the inside of the viewDidLoad initialization of the control, viewWillAppear: dynamic modification inside.
It is recommended to use the first applicable scope more strongly.

On the shelves 应用 may encounter some unexpected situation, not measured Crash , temporary pity dorado small demand, and so on, we can not every time because of a small change on the re App Store -submit, the first not to say App Store the audit time, frequent users to update the application, users will be bored. It would be appropriate to use this article to implement dynamic updates.
First of all the above 动态更新 is a completely detached from the module, and business logic does not have any relationship, only need to deploy once on the line, and other development of the next project can be directly used in the past. The dynamic update here is suitable for the local view, the control modification, if you have other requirements can consider Jspatch, wax, issued script is also a good choice.

Tool article:

Using some of the accessibility tools for UI debugging, it makes it easier for us to see how the view is structured in a project.
Tools for common UI debugging:

  • Captuer View Hiearachy
  • Reveal

Xcode comes with the Captuer View Hiearachy implementation steps:

  • 1. Open Xcode, run the project, select the topDebug
  • 2, Debug View DebuggingShow View Frames
  • 3, Debug View DebuggingCaptuer View Hiearachy

Xcode becomes a three-dimensional view, and the left-hand side of Xcode is a tree-like graph of hierarchical relationships.

The reveal feature is relatively powerful, and is suitable for UI debug view lookups. See the Reveal Integration Guide for how to use it.

    • Ios

IOS Dynamic Update

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.