|
| 1 | +# PushBots Flutter SDK |
| 2 | + |
| 3 | +A library for Dart developers. Help you manage notifications easily and effectively. |
| 4 | + |
| 5 | +## Example project |
| 6 | + |
| 7 | +You can try our sample project inlcuded with the library: |
| 8 | +```shell |
| 9 | +git clone [email protected]:pushbots/flutter-sdk.git |
| 10 | +cd flutter-sdk/example |
| 11 | +flutter run |
| 12 | +``` |
| 13 | + |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Use this package as a library |
| 18 | + |
| 19 | +**1- Add to dependencies:** |
| 20 | + |
| 21 | +Add this to your package's `pubspec.yaml` file below dependencies: |
| 22 | + |
| 23 | + |
| 24 | +````yaml |
| 25 | +dependencies: |
| 26 | + pushbots_flutter: ^1.0.1 |
| 27 | +```` |
| 28 | + |
| 29 | +**2- Install the SDK:** |
| 30 | + |
| 31 | +Run this command on your project: |
| 32 | + |
| 33 | +```` |
| 34 | +$ flutter pub get |
| 35 | +```` |
| 36 | + |
| 37 | +Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more. |
| 38 | + |
| 39 | + |
| 40 | +**3- Add to your project:** |
| 41 | + |
| 42 | +Now in your Dart code `lib/main.dart`, you can start using PushBots SDK: |
| 43 | + |
| 44 | +````dart |
| 45 | +import 'package:pushbots_flutter/pushbots_flutter.dart'; |
| 46 | +```` |
| 47 | + |
| 48 | +### iOS Setup |
| 49 | + |
| 50 | +#### Add PushBots service extension |
| 51 | + |
| 52 | +Follow this article to add PushBots service extension in order to be able to use rich media in your iOS app, you'll find `Flutter SDK additional config` at the end of the article, please make sure to follow it: |
| 53 | + |
| 54 | +https://www.pushbots.help/en/articles/1571650-creating-notification-service-extension |
| 55 | + |
| 56 | +#### Enable push notifications in your app |
| 57 | + |
| 58 | +1. Under targets, click on project name, then click on "+ Capability" |
| 59 | +2. Search for "Push notifications" and click on it, then search for "Background modes", click on it then enable "remote notifications" from the list |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +### Android Setup |
| 64 | + |
| 65 | +Add to `defaultConfig` section, then replace `PUSHBOTS_APPLICATION_ID` and `SENDER_ID` |
| 66 | + |
| 67 | +````gradle |
| 68 | +defaultConfig { |
| 69 | + // Add PushBots integration data |
| 70 | + manifestPlaceholders = [ |
| 71 | + pushbots_app_id : "PUSHBOTS_APPLICATION_ID", |
| 72 | + pushbots_loglevel : "DEBUG", |
| 73 | + google_sender_id : "SENDER_ID" |
| 74 | + ] |
| 75 | +
|
| 76 | + } |
| 77 | +
|
| 78 | +```` |
| 79 | + |
| 80 | +### Flutter Usage |
| 81 | + |
| 82 | +#### Initializing PushBots:- |
| 83 | + |
| 84 | + |
| 85 | +You can start by initializing the `PushBotsFlutter` by calling |
| 86 | + |
| 87 | +````dart |
| 88 | +PushbotsFlutter.initialize("PUSHBOTS_APPLICATIN_ID", "YOUR_WEBAPI_KEY", "YOUR_FCM_APP_ID", "YOUR_PROJECT_ID"); |
| 89 | +```` |
| 90 | + |
| 91 | +to be able to get all firebase cerdentials, check out this article for all details: |
| 92 | +https://www.pushbots.help/en/articles/498201-the-google-part-firebase-credentials |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +Listen for notifiers (receive, open) notifications:- |
| 98 | + |
| 99 | + |
| 100 | +````dart |
| 101 | + PushbotsFlutter.listenForNotificationReceive().stream.listen((onData) { |
| 102 | + print("MAIN, received: " + onData.toString()); |
| 103 | + }); |
| 104 | +
|
| 105 | + PushbotsFlutter.listenForNotificationOpen().stream.listen((onData){ |
| 106 | + print("MAIN, opened: " + onData.toString()); |
| 107 | + }); |
| 108 | +```` |
| 109 | + |
| 110 | + |
| 111 | +Update User info:- |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +````dart |
| 116 | +PushbotsFlutter.setName("Pushbotter"); |
| 117 | +PushbotsFlutter.setFirstName("FirstName"); |
| 118 | +PushbotsFlutter.setLastName("LastName"); |
| 119 | +PushbotsFlutter.setEmail("[email protected]"); |
| 120 | +PushbotsFlutter.setAlias("Alias"); |
| 121 | +PushbotsFlutter.setPhone("phoneNumber"); |
| 122 | +```` |
| 123 | + |
| 124 | +Other Methods: |
| 125 | + |
| 126 | +````dart |
| 127 | +PushbotsFlutter.debug(true); |
| 128 | +//Track event |
| 129 | +PushbotsFlutter.trackEvent("added_to_cart"); |
| 130 | +
|
| 131 | +//ShareLocation with prompting |
| 132 | +PushbotsFlutter.shareLocation(true); |
| 133 | +
|
| 134 | +//unsubscribe user from receiving notifications |
| 135 | +PushbotsFlutter.toggleNotifications(false); |
| 136 | +
|
| 137 | +PushbotsFlutter.setTags(["tag1", "tag2"]); |
| 138 | +
|
| 139 | +PushbotsFlutter.removeTags(["tag1"]); |
| 140 | +
|
| 141 | +// ====== iOS only method ====== |
| 142 | +//Set log level with alert |
| 143 | +//Log Levels : noLog, error, warn, info, verbose |
| 144 | +PushbotsFlutter.setLogLevelWithUI(LogLevels.verbose.index,true); |
| 145 | +//Reset Badge |
| 146 | +PushbotsFlutter.resetBadge(); |
| 147 | +//Set badge |
| 148 | +PushbotsFlutter.setBadge(10); |
| 149 | +//Increment badge count |
| 150 | +PushbotsFlutter.incrementBadgeCountBy(1); |
| 151 | +//Decrement badge count |
| 152 | +PushbotsFlutter.decrementBadgeCountBy(10); |
| 153 | +```` |
| 154 | + |
| 155 | +## Feature and bugs |
| 156 | + |
| 157 | +Please fill issue on https://github.com/pushbots or https://stackoverflow.com/questions/tagged/pushbots |
0 commit comments