Pigeon is a lightweight Swift framework that enables seamless communication between your main iOS app and its extensions through various transport methods.
- 🔄 Bidirectional communication between app and extensions
- 📦 Multiple data transport options:
- File-based communication
- Coordinated file handling
- WatchConnectivity session support (iOS 11.0+)
- 💪 Type-safe message passing
- 🔍 Easy message listening and handling
- ⚡️ Darwin notification support for real-time updates
- iOS 12.0+ / watchOS 4.0+ / macOS 10.13+ / tvOS 12.0+
- Swift 5.10+
- Xcode 15+
Add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/CodingIran/Pigeon.git", from: "0.0.7")
]
-
First, configure your app group identifier in your project capabilities.
-
Initialize Pigeon:
let pigeon = Pigeon(applicationGroupIdentifier: "group.com.your.app")
// Send a message
try pigeon.passMessage("Hello Extensions!", for: "greeting")
// Send with reply handler
try pigeon.passMessage("Ping", for: "ping") { reply in
print("Received reply: \(reply ?? "no reply")")
}
// Start listening
pigeon.listenMessage(for: "greeting") { message, reply in
print("Received: \(message ?? "no message")")
// Send reply if needed
try? reply("Message received!")
}
// Stop listening
pigeon.stopListeningMessage(for: "greeting")
Pigeon supports multiple transport types:
// File-based transport (default)
let pigeon = Pigeon(applicationGroupIdentifier: "group.com.your.app",
transitingType: .file)
// Coordinated file transport
let pigeon = Pigeon(applicationGroupIdentifier: "group.com.your.app",
transitingType: .coordinatedFile)
// WatchConnectivity session transport (iOS 11.0+)
let pigeon = Pigeon(applicationGroupIdentifier: "group.com.your.app",
transitingType: .sessionMessage)
// Clear specific message
try pigeon.clearMessageContents(for: "greeting")
// Clear all messages
try pigeon.clearAllMessageContents()
Pigeon provides detailed error handling through Pigeon.Error
:
applicationGroupIdentifierNotConfigured
messageIdentifierInvalid
sessionUnReachable
fileCoordinatorFailed
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.