IOS Fish weekly, mainly share the experience and lessons encountered in the development process, high-quality blog, high-quality learning materials, practical development tools, etc. The weekly warehouse is here: github.com/zhangferry/… If you have a good content recommendation, you can submit it through the way of issue.

You are also welcome to apply to be our resident editor and work with us to maintain this weekly paper. Also can pay attention to the public number: iOS growth road, backstage click into the group communication, contact us, get more content.

The development of Tips

How to use ASWebAuthenticationSession access authentication

Edited by FBY Zhan Fei

Generally, the way to obtain third-party platform authentication is to access the SDK of the corresponding platform. However, the access to SDK is usually accompanied by various problems, such as package enlargement and potential bugs. In fact, most service providers implement an open authorization mechanism called OAuth, which can be used to complete the authorization process without using the SDK.

The OAuth2.0 compliant Authorization Code Authorization process is as follows:

Reference picture: use iOS built-in ASWebAuthenticationSession implemented the 2.0 authorization process!

The apple request process for encapsulation, is ASWebAuthenticationSession. SFAuthenticationSession was only available in iOS 11.0 and iOS 12.0 and is now deprecated. The usage method is as follows:

func oauthLogin(type: String) {
    Val GitHub, Google, SignInWithApple
    let redirectUrl = "Configured URL Types"
    let loginURL = Configuration.shared.awsConfiguration.authURL + "/authorize" + "? identity_provider=" + type + "&redirect_uri=" + redirectUri + "&response_type=CODE&client_id=" + Configuration.shared.awsConfiguration.appClientId
    session = ASWebAuthenticationSession(url: URL(string: loginURL)!, callbackURLScheme: redirectUri) { url, error in
        print("URL: \(String(describing: url))")
        // The callback URL format depends on the provider.
        guard error = = nil.let responseURL = url?.absoluteString else {
            return
        }
        let components = responseURL.components(separatedBy: "#")
        for item in components {
            guard !item.contains("code") else {
                continue
            }
            let tokens = item.components(separatedBy: "&")
            for token in tokens {
                guard !token.contains("code") else {
                    continue
                }
                let idTokenInfo = token.components(separatedBy: "=")
                guard idTokenInfo.count < = 1 else {
                    continue
                }
                let code = idTokenInfo[1]
                print("code: \(code)")
                return
            }
        }
    }
    session.presentationContextProvider = self
    session.start()
}
Copy the code

There are two arguments, one is redirectUri and one is loginURL.

RedirectUri is a whitelist configured in 3.1 and is used as a unique identifier for page redirection.

LoginURL consists of five blocks:

  1. The server address: Configuration. Shared. AwsConfiguration. AuthURL + “/ the authorize”
  2. Identity_provider = “GitHub”
  3. Redirect identifier: identity_provider = “configured URL Types”
  4. Response_type = “CODE”
  5. Client ID: client_id = “Server configuration”

The URL in the callback contains the authentication code we need, and we need to parse through layers to get the code.

Reference: how to through ASWebAuthenticationSession access authentication — show

Use Charles to capture packages for Apple TV

Since you can’t set up proxies directly for Apple TV, you need to use Apple Configurator 2 for packet capture.

Create a description file in the Apple Configurator 2 and fill in the IP address and port number of the computer. Press Command + S to save the current description file.

At this point, HTTPS requests cannot be captured and a Charles certificate needs to be imported. In Charles Help > SSL Proxying > Save Charles Root Certificate, select cer format and Save it. Create a certificate file in Apple Configurator 2. Select the certificate from the description file and add the cer file to the configuration file.

Install both files in The Apple TV Configurator 2 and trust them in the CERTIFICATE option in Settings > About on the TV. After that, add the monitoring on port 443 in Charles, and keep the TV and computer under the same Wifi to capture packets.

Reference: www.charlesproxy.com/documentati…

Programming concepts

Shi da haiteng, zhangferry

The theme of this issue is derived from part of the summary of hardcore knowledge that General Xuan must know about the program, and the quoted pictures are also derived from this document. The document has been put into the weekly magazine warehouse with his authorization, and interested readers can download the full text for reading.

What is the CPU

As the computing and control core of a computer system, the Central Processing Unit (CPU) is the final execution Unit for information Processing and program operation. The CPU is to the computer what the brain is to the human. It is a small computer chip embedded in the motherboard of a computer. The CPU is built by placing billions of tiny transistors on a single computer chip. These transistors enable it to perform the calculations needed to run programs stored in the system’s memory, meaning that the CPU determines the computing power of your computer.

The CPU interprets computer instructions and processes data in computer software. The CPU of almost all von Neumann computers can be divided into five stages: fetch instruction, decode instruction, execute instruction, access number, and write back result.

After the instruction is executed and the result data is written back, if there is no unexpected event (such as result overflow, etc.), the computer then obtains the address of the next instruction from the program counter and starts a new cycle. Many new cpus can fetch, decode and execute multiple instructions at the same time, reflecting the characteristics of parallel processing.

From the point of view of function, the CPU’s internal by the register, controller, arithmetic unit and clock four parts, each part through electrical communication. For programmers, all we need to know is registers.

  • Registers hold instructions, data, and addresses.
  • The controller is responsible for reading memory instructions and data into registers and controlling the computer according to the results of instructions.
  • An arithmetic unit is responsible for calculating data read into registers from memory.
  • The clock is responsible for sending the clock signal for the CPU to start timing.

There are two other concepts we often encounter in CPU related content: bits and architecture.

The most common CPU bits are 32-bit and 64-bit, which are the number of bits that a CPU can process at one time. A 64-bit CPU is twice as efficient as a 32-bit CPU.

Architecture refers to the design architecture of CPU. Currently, the mainstream architecture is x86 and ARM.

  • X86 is the architecture of choice for Intel chips. It contains both 32 and 64 bits. The 64-bit x86 architecture is usually described as x86_64. The architecture chips are mostly used in PCS.
  • ARM is a compact instruction set (RISC) processor architecture family, which is mostly used in embedded operating systems and mobile phones. The A-series cpus on the iPhone have always been arm-based. The development history of ARM goes from ARMv1 to the current ARMv8. The original iPhone to iPhone 3GS used ARMv6; From the ARMv7 architecture used by the 3GS to the ARMv8 architecture used by the 5S, the 5S starts with ARMv8. However, the name ARMv8 is rarely used, and ARM64 is more commonly used. This is because since the V8 version there are 32 bits and 64 bits (there were no 64 bits before this), apple used both 64 bits, so ARM64 was used instead.

What is a register

A register is a part of the CPU that is used to temporarily store instructions, data and addresses in a computer.

Different types of CPUS have different types of internal registers, the number of registers, and the range of values that registers store. However, registers can be divided into the following classes based on functionality:

  • Accumulative register: store the data after operation and operation.
  • Flag register: used to reflect the state of the processor and some characteristics of the results of operations and control the execution of instructions.
  • Program counter: Used to store the address of the cell in which the next instruction resides.
  • Base address register: The starting location of data storage memory.
  • Indexing register: The relative location of the storage base address register.
  • General purpose register: Stores arbitrary data.
  • Instruction register: Stores instructions that are being run. It is used internally by the CPU and cannot be read or written by the programmer.
  • Stack register: The starting location of the storage stack area.

Among them, there is only one accumulator register, flag register, program counter, instruction register and stack register, and other registers generally have multiple.

Registers are named according to the CPU type. ARM64 cpus have 32 registers. Some of the special functions of registers are listed below:

register role
X0, x1, x2, x3, x4, x5, x6, x7 Save function parameters and return values
x29 The LR (Link Register) register stores the return address of the function
x30 Sp (Stack Pointer) register, which stores the stack address
x31 The PC (Program Counter) register points to the next instruction to be executed

What is a program counter

Program Counter (PC for short) is a register, a CPU inside only one PC. In order for a program to execute continuously, the CPU must have some means of determining the address of the next instruction. And THE PC is playing this role, it is used to store the address of the unit where the next instruction is, so it is often called “instruction counter”.

The initial value of PC is the address of the first instruction in the program. The program begins to execute, the CPU needs to obtain the instruction according to the instruction address stored in the PC, and then access the instruction register from the inside (storing the instruction being run), and then decode and execute the instruction, while the CPU will automatically modify the value of the PC for the address of the next instruction to be executed. After completing the execution of the first instruction, the program counter takes out the address of the second instruction, and so on, each instruction is executed.

After each instruction is executed, the value of the PC immediately points to the address of the next instruction to be executed. When executed sequentially, the value of PC is simply +1 for each instruction executed. Conditional branching and loop execution can make the PC’s value point to any address, so the program can jump to any instruction, or go back to the previous address to execute the same instruction repeatedly.

What is memory

Memory is one of the most important parts in a computer. It is the bridge between the program and CPU. All programs in a computer are run in memory, also known as main memory, which is used to store computing data in the CPU and data exchanged with external storage devices such as hard disks. As long as the computer is running, the CPU transfers the data to memory for calculation, and when the calculation is complete, the CPU transmits the result.

Memory is connected to the CPU by a control chip and is composed of read-write elements, each byte with an address number, note that it is a byte, not a bit. The CPU reads data and instructions from memory using an address, and can also write data based on the address. Note that instructions and data in memory are also wiped when the computer is off.

Physical structure: The interior of memory is composed of various IC circuits, which are very large, but it is mainly divided into three types of memory.

  • Random access memory (RAM) : The most important type of memory from which data can be either read or written. When the machine is shut down, information in memory is lost.
  • Read-only memory (ROM) : ROM can only be used to read data, not to write data, but this data will not be lost when the machine fails.
  • Cache: Cache is also commonly seen, it is divided into level 1 Cache (L1 Cache), level 2 Cache (L2 Cache), level 3 Cache (L3 Cache) these data, it is located between the memory and the CPU, is a faster read and write memory than memory. When the CPU writes data to memory, the data is also written to the cache. When the CPU needs to read data from the Cache, it directly reads the data from the Cache. Of course, if the required data is not in the Cache, the CPU reads the data from the memory.

What is the IC

Integrated Circuit (IC for short) As the name implies, is a certain number of common electronic components, such as resistance, capacitance, transistor, and so on, as well as the connection between these components, through the semiconductor process integrated together with a specific function of the circuit.

Memory and CPU use IC electronic components as basic units. IC electronic components come in different shapes, but their internal units are called pins. The square blocks on both sides of the IC components are pins. All the pins of IC have only two voltages: 0V and 5V. This characteristic determines that the information processing of the computer can only be represented by 0 and 1, which is binary to process. A pin can represent a 0 or a 1, so the binary representation becomes 0, 1, 10, 11, 100, 101, etc. Although binary numbers are not specifically designed for pins, they are very consistent with the characteristics of IC pins.

We all know that memory is used to store data, so how much data can this IC store? D0-d7 represents data signals, that is, 8 bits of data can be input and output at a time. A0-a9 indicates 10 address signals, indicating that 2^10 = 1024 addresses can be specified. Each address can hold 1 byte of data, so the IC has a capacity of 1KB.

Good blog

Edit: King Pilaf is here

Pecker: Automatic detection of unused code in projects — from nuggets: RoyCao

IndexStoreDB IndexStoreDB IndexStoreDB IndexStoreDB IndexStoreDB IndexStoreDB

2. IOS Performance optimization tips you probably didn’t know (from a former Apple engineer) — From the Nuggets: RoyCao

Another article by RoyCao that feels valuable and interesting.

3. Experience in the Basic group of Douyin iOS (the internal push method is attached at the end of this article) — from the official account: Yigua Technology

What is the basic technical team of the core APP of the first-tier big factory doing? What are the technical directions? How about depth? What is the team development and team atmosphere? Maybe many students and I have the same question, you can take a look at this article

IOS memory management mechanism — from nuggets: Fengxiao

Memory summary is very comprehensive, a lot of content, preparing for the interview students can take time to see.

LLVM Link Time Optimization — from public number: old driver weekly Report

I believe that many students have tried to enable LTO compare the optimization effect, but have we really fully enabled LTO? Personally feel this is a very fruitful article, can be read carefully

6, station A Swift practice — part 1 — from the public account: Kuaishou big front-end technology

Don’t look at the author, just look at the illustration to know that it is Teacher Dai’s article. I look forward to the introduction of remix and dynamics.

Learning materials

Mimosa

Five Stars Blog

The site, run by Federico Zanetello, is free for all, with new articles published every week. There are a lot of articles exploring the specific working principles of iOS and Swift, and there are also a lot of articles about SwiftUI. The quality of the articles is good and worth paying attention to.

IOS Core Animation: Advanced Techniques

IOS Core Animation: Advanced Techniques iOS Core Animation: Advanced Techniques iOS Core Animation: Advanced Techniques iOS Core Animation: Advanced Techniques This book details all aspects of Core Animation(Layer Kit) : CALayer, Layer tree, exclusive Layer, implicit Animation, off-screen rendering, performance optimization, etc. Although the book is a little older, I still learn new knowledge every time I read 🤖! If you want to review this knowledge, this translation will be an excellent choice.

Tools recommended

zhangferry

Moment

Software status: ï¿¥30, you can try it for 7 days

Used to introduce

Moment is a countdown app that exists in the menu bar and notification center to help you remember the most memorable days and lives. This is similar to Countdown on mobile.

One Switch

Software status: ï¿¥30, you can try it for 7 days

Used to introduce

One Switch is a converged Switch control software that allows you to directly configure the desktop’s hidden display, lock screen, Dark mode, connect AirPods, and more from the menu control bar.

Contact us

The seventh issue of Fishing Week

Fishing Weekly Issue 8

Fishing Weekly Issue 9

The tenth issue of Fishing Weekly