|
1 |
| -Discourse Mobile App for a Single Site (with support for Push Notifications) |
2 |
| ---- |
| 1 | +## Discourse Mobile App for a Single Site (with support for Push Notifications) |
3 | 2 |
|
4 |
| -Whitelisted iOS app for a single Discourse site that supports Push Notifications via OneSignal. |
| 3 | +Whitelisted iOS/Android app for a single Discourse site that supports push notifications via OneSignal. |
5 | 4 |
|
6 |
| -Built with React Native. Inspired by [DiscourseMobile](https://github.com/discourse/DiscourseMobile). |
7 |
| - |
8 |
| -For a demonstration check out SWAPD or TekInvestor on the App Store or Google Play. |
9 |
| - |
10 |
| -### Do not use this for Android, use web notifications instead |
11 |
| - |
12 |
| -As of September 2018, this app's support for Android will be deprecated. There is now a better way to have notifications in Android from your Discourse site directly. In your Discourse instance, enable the `push notifications prompt` admin setting. This will now let users of your site in applicable browsers (incl. Chrome for Android) see a bar prompting them to enable notifications. And done! |
13 |
| - |
14 |
| -Android-specific instructions below are now outdated. |
| 5 | +For a demonstration check out SWAPD or TekInvestor on the App Store or Google Play. |
15 | 6 |
|
16 | 7 | ### Getting Started
|
17 | 8 |
|
18 |
| -1. Install React Native. |
19 |
| -``` |
20 |
| -npm install -g react-native-cli |
21 |
| -``` |
| 9 | +1. Install your packages: |
22 | 10 |
|
23 |
| -2. Install your packages: |
24 |
| -``` |
25 |
| -npm install |
| 11 | +```bash |
| 12 | +yarn install |
26 | 13 | ```
|
27 | 14 |
|
28 |
| -3. Copy the contents of `default.variables.js` to `app.variables.js` to set your app's variables (site URL, app name, colors, marketing text, etc.). |
| 15 | +2. Link the iOS libraries via |
29 | 16 |
|
30 |
| -4. In the `ios` folder (`cd ios`, run |
| 17 | +```bash |
| 18 | +cd ios && pod install |
31 | 19 | ```
|
32 |
| -pod install |
33 |
| -``` |
34 |
| -This will link the libraries in xCode. |
35 | 20 |
|
36 |
| -5. To run the app locally use: |
| 21 | +3. And run the app in the simulator using: |
37 | 22 |
|
38 |
| -``` |
| 23 | +```bash |
39 | 24 | react-native run-ios
|
| 25 | +# or |
| 26 | +react-native run-android |
40 | 27 | ```
|
41 | 28 |
|
42 |
| -See the [React Native](https://facebook.github.io/react-native/docs/getting-started.html) docs for more details. |
| 29 | +See the [React Native](https://facebook.github.io/react-native/docs/getting-started.html) docs for more details. |
43 | 30 |
|
44 | 31 | ### OneSignal setup
|
45 | 32 |
|
46 |
| -You need to open an account at OneSignal to be able to send Push Notifications (PNs) from your Discourse site, and receive them in the app. Steps: |
| 33 | +You need to open an account at OneSignal to be able to send Push Notifications (PNs) from your Discourse site, and receive them in the app. Steps: |
47 | 34 |
|
48 | 35 | - Register an App ID on the Apple portal (developer.apple.com)
|
49 |
| -- Open an account with [OneSignal](https://www.onesignal.com) (free), create a new app, and generate certificates for iOS and Android |
50 |
| -- Create the provisioning profiles on the Apple portal. You need a distribution profile for pushing to TestFlight and the App Store, and likely an ad-hoc profile for testing quickly on your device. (Note that you may also need a development certificate for testing the app on your device. Step 2 above creates only the production certificate.) |
51 |
| -- Create an iCloud container and associate it with your App ID. |
52 |
| - |
53 |
| -#### OneSignal Discourse Setup |
54 |
| - |
| 36 | +- Open an account with [OneSignal](https://www.onesignal.com) (free), create a new app, and generate certificates for iOS and Android (see Onesignal documentation for steps on each platform) |
55 | 37 | - Add the [discourse-onesignal](https://github.com/pmusaraj/discourse-onesignal/) plugin to your Discourse instance and configure it: enable notifications, add your OneSignal App ID and the OneSignal REST API key.
|
56 |
| -- In your Discourse settings, add your site's home URL to `allowed user api auth redirects` (the app will redirect to your home URL once the user authorizes access for the app in Discourse). |
57 |
| -- ~And add the OneSignal API Endpoint `https://onesignal.com/api/v1/notifications` to `allowed user api push urls`.~ This step is no longer needed, because it causes Discourse to send a second request to OneSignal (which fails). If you have previously added this to your configuration, you should remove it once your app has been updated to include [this commit](https://github.com/pmusaraj/discourse-mobile-single-site-app/commit/c98ab1468ffb03030ff9793d17fe43af99d995a6). |
| 38 | +- in your app's `app.variables.js` file, add the OneSignal App ID |
58 | 39 |
|
59 |
| -#### OneSignal updates to native code |
| 40 | +### Build and release using Fastlane |
60 | 41 |
|
61 |
| -In your app code for either iOS or Android, you need to replace the placeholder OneSignal App ID with your app's OneSignal App ID. |
| 42 | +To simplify managing your app and keeping up with changes in the repo, you can use the included Fastlane scripts. |
62 | 43 |
|
63 |
| -- For iOS, look for `ONESIGNAL_APP_ID` in `ios/DiscoSingle/AppDelegate.m`. |
64 |
| -- For Android, look for `DISCOSINGLE_ONESIGNAL_APP_ID` and `DISCOSINGLE_GOOGLE_PROJECT_NUMBER` in `android/app/build.gradle`. (You will get the Google Project Number while setting up OneSignal for your Android app.) |
| 44 | +#### Initial setup |
65 | 45 |
|
66 |
| -You should now be ready to build and test the app. Note that in iOS, Push Notifications can only be tested on a real device, but the OneSignal console will show attempts to enable Push Notifications from a simulator. |
| 46 | +- Create a private git repository that Fastlane's `match` script uses to generate and update your app's certificates. |
| 47 | +- Copy the `fastlane/example1` folder and the `.env.example1` file and rename them using your app's name (for this guide, we will assume the copied items are `fastlane/yourapp` and `.env.yourapp`). |
| 48 | +- Update the variables in the folder and the ENV file, as well as the logo.png and splash.png images. |
| 49 | +- **iOS**: Create an App Store Connect API Key and follow the instructions in https://docs.fastlane.tools/app-store-connect-api/, and update the `fastlane/yourapp/key.json` file with the key |
| 50 | + details. |
| 51 | +- **Android**: generate or copy over your app's keystore and secrets in the respective files in `fastlane/yourapp`. |
67 | 52 |
|
68 |
| -### Helpful Tools |
| 53 | +You should now be ready to run Fastlane scripts for your app's environment. by appending `--env yourapp` to any Fastlane commands. |
69 | 54 |
|
70 |
| -#### Generating assets |
71 |
| -Use [generator-rn-toolbox](https://github.com/bamlab/generator-rn-toolbox) to setup icons and splash screens for the app: |
| 55 | +To update the app name and assets, run: |
72 | 56 |
|
73 | 57 | ```
|
74 |
| -npm install -g yo generator-rn-toolbox |
75 |
| -
|
76 |
| -yo rn-toolbox:assets --icon icon.png |
77 |
| -yo rn-toolbox:assets --splash splash.png --android |
78 |
| -yo rn-toolbox:assets --splash splash.png --ios |
| 58 | +cd fastlane |
| 59 | +fastlane switch --env yourapp |
79 | 60 | ```
|
80 | 61 |
|
81 |
| -#### Logo for login screen |
82 |
| -The logo file for the login screen is under `js/logo.png`. Replace it with your logo. |
| 62 | +To generate (or update) iOS certificates, run: |
83 | 63 |
|
84 |
| -#### Android build using Gradle |
85 |
| -Follow the [official React Native](https://facebook.github.io/react-native/docs/signed-apk-android.html) instructions on generating a key and an APK for release. Then run |
86 | 64 | ```
|
87 |
| -cd android && ./gradlew assembleRelease |
| 65 | +cd fastlane |
| 66 | +fastlane ios certificates --env yourapp |
88 | 67 | ```
|
89 |
| -and find your release file under `android/app/build/outputs/apk/app-release.apk`. |
90 |
| - |
91 |
| -#### Renaming your App |
92 | 68 |
|
93 |
| -You can rename the app using `react-native-rename`. This is necessary for Android, because it's the only way to change the bundle ID. |
| 69 | +To build your app for iOS, run: |
94 | 70 |
|
95 | 71 | ```
|
96 |
| -npm install react-native-rename -g |
97 |
| -react-native-rename "NewName" -b com.yourco.yourappid |
| 72 | +cd fastlane |
| 73 | +fastlane ios install --env yourapp |
| 74 | +# will install the app on a connected device or simulator |
| 75 | +
|
| 76 | +fastlane ios release --env yourapp |
| 77 | +# will build and upload the app to TestFlight |
| 78 | +
|
98 | 79 | ```
|
99 | 80 |
|
100 |
| -(The bundle name specified by `-b` above only applies to Android, to change your iOS bundle ID, use Xcode.) |
| 81 | +To build your app for Android, run: |
101 | 82 |
|
102 |
| -After renaming the app, you need to manually edit some files in subfolders under `android/app/src/main/java`, and replace `com.discosingle;` at the beginning of every file with your new bundle ID. The rename script does it for `MainActivity.java` and `MainApplication.java`, you need to manually do this for the remaining files. |
| 83 | +``` |
| 84 | +cd fastlane |
| 85 | +fastlane android apk --env yourapp |
| 86 | +# will build an apk in android/app/build/outputs/apk/ |
103 | 87 |
|
104 |
| -### Troubleshooting |
| 88 | +fastlane android release --env yourapp |
| 89 | +# will create a bundle android/app/build/outputs/bundle/ |
105 | 90 |
|
106 |
| -- Android file uploads may fail. The app uses https://github.com/dahjelle/react-native-android-webview-file-image-upload to enable file uploads in WebView, but it's not tested with all versions of Android. |
107 |
| -- If you have already checked out the project, and renamed the app, you may run into a variety of file conflicts if you pull updates. This is especially the case if the React Native version in the project has been updated. This is normal, and a better course of action is to check out a fresh copy, and reapply your changes and the rename. |
| 91 | +``` |
0 commit comments