Overview
The article discusses the implementation of a messaging layer between the native and web portions of the LinkedIn iPad app using WebSockets. It highlights the challenges faced with URL scheme navigation and how WebSockets provide a faster and more reliable communication method, while also addressing issues encountered during implementation.
What You'll Learn
1
How to implement WebSockets for communication between JavaScript and native code
2
Why using a hybrid approach can mitigate issues with WebSocket connections
3
When to use URL schemes versus WebSockets in iOS applications
Prerequisites & Requirements
- Understanding of iOS app development and JavaScript
- Familiarity with WebSocket implementation(optional)
Key Questions Answered
What are the limitations of using URL scheme navigation in iOS apps?
URL scheme navigation in iOS apps can lead to unpredictable behavior when sending multiple messages quickly, resulting in lost messages. Additionally, it can cause the UIWebView to become unresponsive after navigation attempts, limiting its functionality.
How do WebSockets improve communication in the LinkedIn iPad app?
WebSockets allow for asynchronous communication between JavaScript and native code without payload limits, making them faster and more reliable than URL scheme navigation. They also eliminate the need to encode JSON strings as URL parameters, enhancing performance.
What issues were encountered with WebSocket implementation in the LinkedIn iPad app?
The implementation faced issues such as crashes when a proxy was defined on the device, and problems with maintaining valid WebSocket connections when the device was asleep. These issues necessitated a fallback to URL scheme navigation under certain conditions.
What is the hybrid approach to messaging used in the LinkedIn iPad app?
The hybrid approach allows the app to use WebSockets when possible, while falling back to a modified URL scheme (webmsg://) when WebSockets cannot be used. This ensures that messaging remains functional even in adverse conditions.
Key Statistics & Figures
Average round-trip message time
48.09ms
This average time was observed during tests comparing WebSocket, webmsg://, and original URL scheme implementations.
Fastest round-trip message time
41ms
This was the fastest recorded time for the original URL scheme during testing.
Slowest round-trip message time
130ms
This was the slowest recorded time for the original URL scheme during testing.
Technologies & Tools
Some links below are affiliate links. We may earn a commission if you make a purchase.
Communication Protocol
Websocket
Used for asynchronous communication between the JavaScript and native portions of the LinkedIn iPad app.
Programming Language
Javascript
Used to implement the messaging layer and handle communication with the WebSocket server.
Programming Language
Objective C
Used to write the WebSocket server for the LinkedIn iPad app.
Key Actionable Insights
1Implement WebSockets in your iOS applications to enhance communication speed and reliability.Using WebSockets can significantly reduce message delivery times and improve the overall user experience, especially in messaging-heavy applications.
2Consider a hybrid messaging approach to ensure functionality in varying network conditions.By combining WebSockets with a fallback mechanism like URL schemes, you can maintain communication even when WebSocket connections are unstable or unavailable.
3Regularly test your WebSocket implementation across different devices and network configurations.This will help identify potential issues, such as those related to proxies, and ensure that your app remains robust and user-friendly.
Common Pitfalls
1
Assuming WebSocket connections will always be stable can lead to crashes and unresponsive behavior.
It's important to account for network conditions and implement fallback mechanisms to handle cases where WebSocket connections fail or become invalid.
2
Overloading the URL scheme with too many rapid messages can result in lost communications.
When using URL schemes, ensure that messages are queued properly to avoid cancellation of earlier messages, which can lead to inconsistent app behavior.
Related Concepts
Websockets And Their Applications In Mobile Development
Asynchronous Communication Patterns In Ios
Hybrid Application Architectures