Introduction
Welcome to the documentation for mmwormhole, a Cocoapod that allows you to easily pass data between applications using App Groups and WatchConnectivity.
Why use mmwormhole?
mmwormhole simplifies the process of data sharing between iOS and WatchOS applications by abstracting the underlying complexity of App Groups and WatchConnectivity APIs.
Key features of mmwormhole include:
- Straightforward API for sending and receiving data
- Automatic handling of different data types
- Seamless integration with App Groups and WatchConnectivity
By using mmwormhole, you can focus on building great applications without getting bogged down in the details of data synchronization.
Installation
To install mmwormhole, you can use Cocoapods. Add the following line to your Podfile:
pod 'mmwormhole'
Then run the following command:
pod install
Usage
Using mmwormhole is simple. Here are the basic steps:
- Create an instance of mmwormhole in both the sender and receiver applications:
- Send data from the sender application:
- Receive data in the receiver application:
// Sender application
let wormhole = MMWormhole(applicationGroupIdentifier: "group.com.example.myapp", optionalDirectory: "wormhole")
// Receiver application
let wormhole = MMWormhole(applicationGroupIdentifier: "group.com.example.myapp", optionalDirectory: "wormhole")
wormhole.passMessageObject(message, identifier: "myMessageIdentifier")
wormhole.listenForMessage(withIdentifier: "myMessageIdentifier") { (messageObject) in
if let message = messageObject as? MyMessageType {
// Process the received message
}
}
Advanced Topics
Data Types and Serialization
mmwormhole automatically handles serialization and deserialization of common data types such as strings, numbers, dictionaries, and arrays. For custom data types, you can use NSCoding or convert them to supported types before passing through the wormhole.
Multiple Wormholes
In some cases, you may need to use multiple wormholes within the same application group. This can be useful when sharing data between different components or features. To achieve this, create separate instances of MMWormhole with different directories within the same application group identifier. Each instance will maintain its own communication channel.
Error Handling
mmwormhole provides error handling by exposing a delegate protocol, MMWormholeDelegate. By conforming to this protocol, you can handle any potential errors that may occur during data transfer. Refer to the documentation for the MMWormholeDelegate protocol for more details.
If necessary, you can also listen for file transfers and handle them manually using the MMWormholeFileTransferDelegate protocol.
Conclusion
mmwormhole simplifies the process of sharing data between iOS and WatchOS applications using App Groups and WatchConnectivity. By abstracting the underlying complexity, mmwormhole allows you to focus on building great applications without worrying about the details of data synchronization.
For more information, refer to the official mmwormhole documentation.