In the first part, we discussed about iOS developer interview questions related to polymorphism, encapsulation, MVC pattern, and more. Here’s the next part of the commonly asked questions.
WHAT IS THE RESPONDER CHAIN?
Answer: The Responder Chain mechanism handles user interaction with UI and external events in iOS.
For touch events:
On calling an object of type UIViewin (hit-testing), an object of type UIWindowstries passes a touch to the former.
In case of inability to process the UIViewthis touch, the mechanism transmits the process to the component’s superview. If it still cannot process, the mechanism keeps transmitting to the higher level until processed. An instance is when an object is invisible or cannot interact with itself.
Class UIApplication, UIViewController, and UIViewinherited from the class UIResponder.
The class UIResponder defines the order in which objects handle events (touch, text change, events from UI elements like buttons). In addition, it UIResponderdeclares methods that allow objects to determine who will be the first to respond and process messages:
- becomeFirstResponder – When the systems sends events, the recipient object of the message receives them first
- resignFirstResponder – the recipient object refuses to process messages first
HOW DO PUSH NOTIFICATIONS WORK?
Answer: Push notification is a short message comprising a token of a device, payload, and some other information. The payload is the actual data that the server sends to the device. The scheme of work is:
- The Apple Push Notification Service (APNS) requests a token from the device, a kind of key considered as an “address”.
- There is a server (our or another service).
- The application sends a token to the server which is busy sending push notifications.
- In case, an event for your application occurs, the server sends a push notification to APNS.
- Then, APNS sends a push notification to the user’s device.
Consider the following points to develop push notifications:
- iPhone, iPad or iPod touch: Push notifications do not work in the simulator, so you need a real device for testing.
- Registration in the iOS Developer Program: For each application that integrates Push Notifications mechanism, create new App ID, provisioning profile, and SSL certificate for the server. iOS Provisioning Portal becomes the base to perform these actions.
- You must create a provisioning profile and an SSL certificate.
- A server connected to the Internet. The server always sends push notifications.
- Push notifications are something quite small; the size of the payload cannot exceed 256 bytes. This is same as allowing you to place an SMS or a tweet. The push server will not send online breaks and spaces.
Thin moments when working with push notifications:
- They are not reliable! There is no guarantee for the delivery of push notifications even after APNS accepts them.
- Once your server generates a push notification, it sends it unanswered to APNS. There is no way to know the status of delivery of the notification to the end user after sending. Delivery time can vary from a few seconds to half an hour.
- In addition, i-delay users may not receive push notifications all the time. For example, near there is no Wi-Fi network with Internet access or the device can be turned off at all.
- APNS will attempt to deliver the last notification sent when the device becomes available for reception. But there’s a time limitation on these attempts. After the timeout, it loses the push notification forever!
- They can be expensive! Adding push-functionality to the application is simple and inexpensive if you own the data. However, if you have many users, or you need to request data, the costs increase dramatically.
WHAT ARE SOLID PRINCIPLES?
S – Single responsibility principle – The principle of a single duty wherein each class has a single responsibility assigned.
O – Open/closed principle – The principle of openness/closure: Software entities must be open for expansion, but not closed for modification.
L – Liskov substitution principle – The functions that use the base type must be able to use subtypes of the base type without knowing it.
I – Interface segregation principle – Many interfaces are better than one universal interface.
D – Dependency inversion principle – Dependency inversion principle: Abstractions build the dependencies within the system. The top-level modules do not depend on the lower-level modules. Abstractions should not depend on details. Details should depend on abstractions.
WHAT IS THE LIFE CYCLE OF AN IOS APPLICATION?
Answer: Application states
|Not running||User didn’t start the application, or the user started the application but the system interrupted its execution|
|Inactive||The application is running in the foreground, but is not accepting events at the moment. Although it can execute some other code at this time. The application usually stays in this state for a very short time since it immediately goes into another state.|
|Active||The application works in the foreground and receives events. This is the normal mode for applications in the foreground.|
|Background||The application is in the background and executes the code. Most applications enter this state for a short while during the transition to the suspended state. However, an application that requests an additional run-time may remain in this state for a while. In addition, an application that runs directly in the background immediately enters the Background state, not the Inactive state.|
|Suspended||The application is in the background but does not execute the code. The system automatically translates applications into this state and does not notify them of this. The application is in the suspended state & remains in memory but executes none code. In case of low memory state, system can delete paused applications without notification to make room for foreground applications.|
The second part of iOS developer interview questions and answers ends here. Check out the part 3 for more questions.
Did you find the part 2 of iOS developer interview questions useful? Feel free to provide your comments and concerns in the below comment section.