|
1 | 1 | # PushNotificationSimulation |
2 | 2 |
|
3 | | -TODO |
| 3 | +`PushNotificationSimulation` helps in simulating push notifications in the application during development. |
| 4 | + |
| 5 | +[](https://swift.org/) |
| 6 | +[](https://cocoapods.org/pods/PushNotificationSimulation) |
| 7 | +[](https://github.com/Carthage/Carthage) |
| 8 | +[](http://cocoadocs.org/docsets/PuzzleMaker) |
| 9 | +[](https://github.com/PGSSoft/PuzzleMaker) |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +Using [Cocoapods](https://cocoapods.org/) with Podfile: |
| 14 | + |
| 15 | +```ruby |
| 16 | +pod 'PushNotificationSimulation' |
| 17 | +``` |
| 18 | + |
| 19 | +or using [Carthage](https://github.com/Carthage/Carthage) and add a line to `Cartfile`: |
| 20 | + |
| 21 | +``` |
| 22 | +github "pwlkania/PushNotificationSimulation" |
| 23 | +``` |
| 24 | + |
| 25 | +or Swift Package Manager (Xcode 11): |
| 26 | + |
| 27 | +Coming soon! |
| 28 | + |
| 29 | +## Requirements |
| 30 | + |
| 31 | +iOS 11.0 |
| 32 | + |
| 33 | +## Initialization |
| 34 | + |
| 35 | +First of all, you need to modify your `AppDelegate.swift` file: |
| 36 | + |
| 37 | +Import `PushNotificationSimulation` framework (if needed): |
| 38 | + |
| 39 | +```swift |
| 40 | +import PushNotificationSimulation |
| 41 | +``` |
| 42 | + |
| 43 | +Implement `PushNotificationSimulation` protocol: |
| 44 | + |
| 45 | +```swift |
| 46 | +#if DEBUG |
| 47 | +extension AppDelegate: PushNotificationSimulation { } |
| 48 | +#endif |
| 49 | +``` |
| 50 | + |
| 51 | +Implement required property from `PushNotificationSimulation` protocol: |
| 52 | + |
| 53 | +```swift |
| 54 | +#if DEBUG |
| 55 | +weak var app: UIApplication? |
| 56 | +#endif |
| 57 | +``` |
| 58 | + |
| 59 | +Assign `UIApplication` object to `app` property: |
| 60 | + |
| 61 | +```swift |
| 62 | +func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { |
| 63 | + // Your code... |
| 64 | + |
| 65 | + #if DEBUG |
| 66 | + app = application |
| 67 | + #endif |
| 68 | + |
| 69 | + // Your code... |
| 70 | + return true |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +Your `AppDelegate.swfit` file should look similar to this: |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +## Usage |
| 79 | + |
| 80 | +Using breakpoints with debugger command (suggested approach) - example: |
| 81 | + |
| 82 | +``` |
| 83 | +e simPush(payload: "{\"aps\":{\"alert\":{\"title\":\"Game Request\",\"subtitle\":\"Five Card Draw\",\"body\":\"Bob wants to play poker\"},\"category\":\"GAME_INVITATION\"},\"gameID\":\"12345678\"}", delay: 3) |
| 84 | +``` |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +You can also use `simPush(...)` global function directly in the code. However it might cause issues when code is not deactivated in production version of your application. Be careful. |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +## License |
| 93 | + |
| 94 | +The project is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). |
0 commit comments