Development tools

1. CocoaPods 

CocoaPods is a project dependency management tool that provides management of third-party open source libraries. Such as:

  1. There is no need to set the special compilation parameter -fno-objc-arc for some open source libraries.
  2. There is no need to manually add the corresponding system dependent library framework.
  3. Easy to update open source libraries

1.1 installation CocoaPods

Run the following command on the terminal:

  • sudo gem install cocoapods
  • pod  setup

If your gem is too old, you can update it with sudo gem update — system

In addition, rubygems.org, the ruby software source of MAC, is blocked because it uses Amazon’s cloud service. The ruby source needs to be updated as follows:

  • gem sources –remove https://rubygems.org/

  • gem sources -a http://ruby.taobao.org/
  • gem sources -l

1.2 use CocoaPods

To use CocoaPods, you just need to put the third-party open source libraries you’re using into your Podfile in your project directory:



Then go to the terminal CD and run pod Install. Each time you change the Podfile, you need to re-execute the POD update name (if you encounter a project conflict, use: pod update –verbose –no-repo-update)


2. Network packet analysis tool Charles

2.1 Main functions of Charles

  1. SSL proxy is supported. Requests for analyzing SSL can be intercepted. SSL– links with associated certificate encryption.
  2. Supports flow control. You can simulate slow networks and requests with long wait times.
  3. AJAX debugging is supported. Jsons or XML data can be automatically formatted for easy viewing.
  4. Support FOR AMF debugging, you can format Flash Remoting or Flex Remoting information for easy viewing.
  5. Supports resending network requests, facilitating back-end debugging.
  6. Network request parameters can be modified.
  7. Interception and dynamic modification of network requests are supported.
  8. Check HTML, CSS, and RSS content for W3C standards (validator.w3.org/).)

2.2 Charles Function analysis

Portal: About Charles’ specific functions in app development – Tang Qiao’s blog.


3. Mark Eel (Mark Man Portal: www.getmarkman.com)

Tagging is a free tagging tool that makes it easy to output the size, color, margin, description, etc of elements on a design drawing. The diagram below:

        


Ii. Development practice

1 UIWebView or WKWebView(iOS8.0) mixed programming

Webview-based hybrid programming is the use of native controls and WebView to show the application interface.

1.1 When should webView be used?

  1. Typography is complex. Including text and text mix, link support click.
  2. The interface changes frequently
  3. The interface is not complex to the user’s interaction requirements

2. Hybrid programming module rendering engine

In real development, the webView control accepts an HTML content that renders the corresponding interface.

WWWWW

  1. NSString *webContent = [NSString stringWithFormat:@"<html><head></head><body>%@</body></html>",webContent];  baseURL:nil];Copy the code
  2. [_webView loadHTMLString:webContent];Copy the code

It is possible to load HTML content with tags (such as product details) and no user interaction if you use method 1 to simply present something. As can be seen from the above, this is not convenient to expand:

  • Fuzzy content is mixed with code, making it hard to read and hard to change.
  • The rendering logic of the template is done using a simple [NSString stringWithFormat:], with a single function (shown in the secondary processing of the data).

   
2.2 Method 2: Module rendering engine

2.2.1 MGTemplateEngine (portal: mattgemmell.com/mgtemplatee…). , its module rendering engine is relatively heavyweight, can customize Filter. It relies on RegexKit, a regular expression utility class that provides powerful regular expression matching and replacement capabilities.

2.2.2 GRMustache rendering is lightweight and match and replace rules are provided by the author. (Portal: Download address)

  • To plug Mustache into a project, use POD.
  • Create corresponding HTML, CSS, js files. Fill in various documents.

Here’s a simple example:

Create a file named test.html

<html> 
 <head> 
css--->%@
  </head> 
 <body>
 <h1>
  {{ title }}
  </h1> 
 <p>
  {{ content }}
  </p>
js->%@
  </body> 
  </html>Copy the code

The file is then read into memory in code and the rendered HTML is generated using the renderObject method of GRMustache. The code:

NSURL *urlPath = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"html"];
NSString *html = [NSString stringWithContentsOfURL:urlPath encoding:NSUTF8StringEncoding error:nil];

NSDictionary *renderObject = @{@"title": @"I am the title."The @"content": @"I am the content"};
NSString *content = [GRMustacheTemplate renderObject:renderObject fromString:html error: nil];

[_webView loadHTMLString:content baseURL:nil];
Copy the code

So you’ve done a successful HTML rendering using the GRMustache module engine.

Note: The key of the renderObject must correspond to the value set in the HTML.


Development skills

3.1 Delete unused pictures

After several iterations of the app, some pictures will remain after being replaced. How do you know what image resources are not being used in your project? Provide a little tool,

Jeffhodnett-unused or LSUnusedResources (github)

After downloading, you can run the project.

3.2 Packing IPA Packages

According to the normal operation of Xcode documents, packaging is very slow. In order to provide efficiency, I provide two methods. The principle of these two methods is the same.

  • All breakpoints in the project are removed and Command +B compiles the program
  • Create a file called Payload
  • Find the project directory pruacute-> xxx.app (show in finder) and copy the program in this directory to the Payload file, reduce the directory and change the suffix to IPa.

Another approach is to have scripts for packaging. Create the build_app.sh file with sublime tool

mkdir ${appName}         
mkdir ${appName}/Payload
cp -r ${appName}.app ${appName}/Payload/${appName}.app
cp Icon.png ${appName}/iTunesArtwork
cd ${appName}
zip -r ${appName}.ipa Payload iTunesArtwork
ipaName=Gemall_${version}_${environmental}_`date +20%y%m%d`_01.ipa
mv $project_path/${appName}/${appName}.ipa  $project_path/${ipaName}
rm -rf $project_path/${appName}
exit 0

# #
#appName Project name
# version version number
#environment Indicates the interface environment
#project_path The absolute path of the project
Copy the code

To pack, run sh build_app.sh on the terminal.

3.3 Fixed unknown crash on line

3.3.1 Application Received Signal SIGABRT

How it works: in Xcode 8, when you have a resource file [containing 16 bitmaps] or [image display mode γ value]'P3'] This problem occurs when the target is set to iOS 9.3 or below. If your app needs to support wide gamue display, you must set target to iOS 9.3+. Conversely, if your app does not need wide gamue support and you want to work with pre-ios 9.3 projects, you need to set all 16-bit or display modes to iOS 9.3'P3'Images are all replaced with SRGB color images in 8-bit mode.Copy the code

Steps:

  1. Find the project directory Prudimension ->xxx.app (show in Finder)
  2. On terminal CD… /your.app
  3. find . -name ‘Assets.car’

  4. sudo xcrun –sdk iphoneos assetutil –info Assets.car > /tmp/Assets.json

  5. open /tmp/Assets.json

Open assets.json and look for something that contains “DisplayGamut” :” P3 “or related content. If so, ask UI to cut it up again.

Iv. Development and sharing

Overview of iOS performance optimization: Basic tools, service optimization, memory optimization, lag optimization, layout optimization, battery optimization, installation package slimming, startup optimization, network optimization, etc. — Share connection