|
| 1 | +# GoodRemoteNotifier |
| 2 | + |
| 3 | +`GoodRemoteNotifier` is a Swift package designed to fetch and display remote notifications based on a JSON template. It allows you to integrate messages, titles, and buttons for different languages, all fetched from Firebase Remote Config. |
| 4 | + |
| 5 | +This package is useful for applications that need to display localized messages and UI elements like update notifications, with multiple language capabilities and appearance customization. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Fetches remote configuration based on a given topic. |
| 10 | +- Supports multi-language messages for app notifications (e.g., update alerts). |
| 11 | +- Displays customizable messages, titles, and buttons based on the selected language. |
| 12 | +- Supports debug mode for easier testing. |
| 13 | +- Allows customization of the appearance of messages. |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +You can install `GoodRemoteNotifier` via Swift Package Manager by adding it to your `Package.swift` file: |
| 18 | + |
| 19 | +```swift |
| 20 | +dependencies: [ |
| 21 | + .package(url: "https://github.com/yourusername/GoodRemoteNotifier.git", from: "1.0.0") |
| 22 | +] |
| 23 | +``` |
| 24 | + |
| 25 | +## Configuration Data |
| 26 | + |
| 27 | +The remote configuration is fetched from Firebase Remote Config in JSON format. The JSON template for the configuration should follow this structure: |
| 28 | + |
| 29 | +- **frequency** (optional): Defines how often the notification should appear (e.g., once, daily, weekly, monthly). If not defined, the default value is `once`. |
| 30 | +- **title**: Localized titles for the notification. These will be displayed based on the user's selected language. |
| 31 | +- **message**: Localized messages containing the content of the notification. These messages explain what's new in the app or what the user should do. |
| 32 | +- **updateButton** (optional): Localized text for the action button, used for opening the app in the app store. |
| 33 | +- **closeButton** (optional): Localized text for the close button, used for dismissing the notification. If not defined, the message is not dismissible. |
| 34 | + |
| 35 | +> **⚠️ Important**: If the `frequency`, `title`, or `message` values change for the specified language, the notification will be treated as a new message. |
| 36 | +
|
| 37 | +```JSON |
| 38 | +{ |
| 39 | + "frequency": "daily", |
| 40 | + "title": { |
| 41 | + "en": "An Update is Available!", |
| 42 | + "de": "Ein Update ist verfügbar!" |
| 43 | + }, |
| 44 | + "message": { |
| 45 | + "en": "The new version of the app is here...", |
| 46 | + "de": "Die neue Version der App ist da..." |
| 47 | + }, |
| 48 | + "updateButton": { |
| 49 | + "en": "Update Now", |
| 50 | + "de": "Jetzt aktualisieren" |
| 51 | + }, |
| 52 | + "closeButton": { |
| 53 | + "en": "Close", |
| 54 | + "de": "Schließen" |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +## Usage |
| 60 | + |
| 61 | +Make sure that you have imported the `GoogleService-Info.plist` file into your project. |
| 62 | +Additionally, ensure that `Firebase.configure()` is called before initializing the GoodRemote notifier. |
| 63 | + |
| 64 | +Initialize the notifier in `AppDelegate` or in the `@main` App struct for SwiftUI. It will automatically listen for the selected topic and display notifications based on the chosen frequency. |
| 65 | + |
| 66 | +```Swift |
| 67 | +import GoodRemoteNotifier |
| 68 | + |
| 69 | +let notifier = GoodRemoteNotifier( |
| 70 | + appId: "123456789", // The App Store ID of the app for redirection. |
| 71 | + topic: "update", // Firebase remote config parameter key |
| 72 | + selectedLanguage: { "en" }, |
| 73 | + appearance: RemoteMessageAppearance.default, // Configuration for how remote messages should be displayed. |
| 74 | + isDebugSession: { false } // If true, disables caching and sets the minimum fetching interval to 0. |
| 75 | +) |
| 76 | +``` |
| 77 | + |
| 78 | +## License |
| 79 | + |
| 80 | +`GoodRemoteNotifier` is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details. |
0 commit comments