1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-13 22:12:50 +02:00

RN upgrade: Restore iOS notification feature

This commit is contained in:
Laurent Cozic
2020-02-09 16:29:46 +00:00
parent 813137efc9
commit 46ca24cf9d
5 changed files with 90 additions and 118 deletions

View File

@@ -12,7 +12,7 @@
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
// #import <React/RCTPushNotificationManager.h>
#import <RNCPushNotificationIOS.h>
@implementation AppDelegate
@@ -33,12 +33,45 @@
return YES;
}
// =====================================================
// For @react-native-community/push-notification-ios
// =====================================================
// Required to register for notifications
// - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings]; } // Required for the register event.
// - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification.
// - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event.
// - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for the localNotification event.
// - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [RCTPushNotificationManager didReceiveLocalNotification:notification]; }
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
}
// =====================================================
// /For @react-native-community/push-notification-ios
// =====================================================
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{

View File

@@ -103,6 +103,8 @@ PODS:
- React-Core (= 0.60.6)
- rn-fetch-blob (0.12.0):
- React-Core
- RNCPushNotificationIOS (1.0.5):
- React
- RNFileViewer (1.0.1):
- React
- RNFS (2.11.17):
@@ -143,6 +145,7 @@ DEPENDENCIES:
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
- React-RCTWebSocket (from `../node_modules/react-native/Libraries/WebSocket`)
- rn-fetch-blob (from `../node_modules/rn-fetch-blob`)
- "RNCPushNotificationIOS (from `../node_modules/@react-native-community/push-notification-ios`)"
- RNFileViewer (from `../node_modules/react-native-file-viewer/ios`)
- RNFS (from `../node_modules/react-native-fs`)
- RNSecureRandom (from `../node_modules/react-native-securerandom`)
@@ -212,6 +215,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/Libraries/WebSocket"
rn-fetch-blob:
:path: "../node_modules/rn-fetch-blob"
RNCPushNotificationIOS:
:path: "../node_modules/@react-native-community/push-notification-ios"
RNFileViewer:
:path: "../node_modules/react-native-file-viewer/ios"
RNFS:
@@ -254,6 +259,7 @@ SPEC CHECKSUMS:
React-RCTVibration: 7655d72dfb919dd6d8e135ca108a5a2bd9fcd7b4
React-RCTWebSocket: 7cd2c8d0f8ddd680dc76404defba7ab1f56b83af
rn-fetch-blob: f065bb7ab7fb48dd002629f8bdcb0336602d3cba
RNCPushNotificationIOS: 30ed75aa2981a4ee00b8a2c46599ff18a9c7fcf6
RNFileViewer: 5047ecf40477339723cc08abd55b5ebcefcef4b5
RNFS: 416676c3a9ae404454bade10e3d78147c7c33a40
RNSecureRandom: 1f19ad1492f7ed416b8fc79e92216a1f73f13a4c

View File

@@ -1,21 +1,21 @@
// const { PushNotificationIOS } = require('react-native');
import PushNotificationIOS from '@react-native-community/push-notification-ios';
class AlarmServiceDriver {
constructor() {
this.hasPermission_ = null;
this.inAppNotificationHandler_ = null;
// PushNotificationIOS.addEventListener('localNotification', instance => {
// if (!this.inAppNotificationHandler_) return;
PushNotificationIOS.addEventListener('localNotification', instance => {
if (!this.inAppNotificationHandler_) return;
// if (!instance || !instance._data || !instance._data.id) {
// console.warn('PushNotificationIOS.addEventListener: Did not receive a proper notification instance');
// return;
// }
if (!instance || !instance._data || !instance._data.id) {
console.warn('PushNotificationIOS.addEventListener: Did not receive a proper notification instance');
return;
}
// const id = instance._data.id;
// this.inAppNotificationHandler_(id);
// });
const id = instance._data.id;
this.inAppNotificationHandler_(id);
});
}
hasPersistentNotifications() {
@@ -36,28 +36,26 @@ class AlarmServiceDriver {
if (this.hasPermission_ !== null) return this.hasPermission_;
return new Promise((resolve) => {
this.hasPermission_ = true;
resolve(true);
// PushNotificationIOS.checkPermissions(async perm => {
// const ok = await this.hasPermissions(perm);
// this.hasPermission_ = ok;
// resolve(ok);
// });
PushNotificationIOS.checkPermissions(async perm => {
const ok = await this.hasPermissions(perm);
this.hasPermission_ = ok;
resolve(ok);
});
});
}
async requestPermissions() {
// const newPerm = await PushNotificationIOS.requestPermissions({
// alert: 1,
// badge: 1,
// sound: 1,
// });
// this.hasPermission_ = null;
// return this.hasPermissions(newPerm);
const newPerm = await PushNotificationIOS.requestPermissions({
alert: 1,
badge: 1,
sound: 1,
});
this.hasPermission_ = null;
return this.hasPermissions(newPerm);
}
async clearNotification(/* id */) {
// PushNotificationIOS.cancelLocalNotifications({ id: `${id}` });
async clearNotification(id) {
PushNotificationIOS.cancelLocalNotifications({ id: `${id}` });
}
async scheduleNotification(notification) {
@@ -70,13 +68,13 @@ class AlarmServiceDriver {
const iosNotification = {
id: `${notification.id}`,
alertTitle: notification.title,
fireDate: notification.date,
fireDate: notification.date.toISOString(),
userInfo: { id: `${notification.id}` },
};
if ('body' in notification) iosNotification.alertBody = notification.body;
// PushNotificationIOS.scheduleLocalNotification(iosNotification);
PushNotificationIOS.scheduleLocalNotification(iosNotification);
}
}

View File

@@ -2084,6 +2084,24 @@
}
}
},
"@react-native-community/push-notification-ios": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@react-native-community/push-notification-ios/-/push-notification-ios-1.0.5.tgz",
"integrity": "sha512-4JO5XjmzD4EoReHVxMOYni03Twwuq39oyAIk2U62oIjkIE23tTBblC2KC2IS/iadRyJTg7MQ0LtBat2zse9WQg==",
"requires": {
"invariant": "^2.2.4"
},
"dependencies": {
"invariant": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz",
"integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==",
"requires": {
"loose-envify": "^1.0.0"
}
}
}
},
"@react-native-community/slider": {
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/@react-native-community/slider/-/slider-2.0.8.tgz",
@@ -2445,15 +2463,6 @@
"resolved": "https://registry.npmjs.org/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-7.0.0-beta.0.tgz",
"integrity": "sha512-Xj9XuRuz3nTSbaTXWv3itLOcxyF4oPD8douBBmj7U9BBC6nEBYfyOJYQMf/8PJAFotC62UY5dFfIGEPr7WswzQ=="
},
"babel-plugin-transform-define": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/babel-plugin-transform-define/-/babel-plugin-transform-define-1.3.1.tgz",
"integrity": "sha512-JXZ1xE9jIbKCGYZ4wbSMPSI5mdS4DRLi5+SkTHgZqWn5YIf/EucykkzUsPmzJlpkX8fsMVdLnA5vt/LvT97Zbg==",
"requires": {
"lodash": "^4.17.11",
"traverse": "0.6.6"
}
},
"babel-preset-fbjs": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/babel-preset-fbjs/-/babel-preset-fbjs-3.3.0.tgz",
@@ -2827,11 +2836,6 @@
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz",
"integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ=="
},
"clamp": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/clamp/-/clamp-1.0.1.tgz",
"integrity": "sha1-ZqDmQBGBbjcZaCj9yMjBRzEshjQ="
},
"class-utils": {
"version": "0.3.6",
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
@@ -6279,21 +6283,6 @@
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw=="
},
"path-to-regexp": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz",
"integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=",
"requires": {
"isarray": "0.0.1"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
}
}
},
"path-type": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz",
@@ -6860,32 +6849,11 @@
}
}
},
"react-native-dismiss-keyboard": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/react-native-dismiss-keyboard/-/react-native-dismiss-keyboard-1.0.0.tgz",
"integrity": "sha1-MohiQrPyMX4SHzrrmwpYXiuHm0k="
},
"react-native-document-picker": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/react-native-document-picker/-/react-native-document-picker-2.3.0.tgz",
"integrity": "sha512-bHMyAOzFl+II0ZdfzobKsZKvTErmXfmQGalpxpGbeN8+/uhfhUcdp4WuIMecZhFyX6rbj3h3XXLdA12hVlGgmw=="
},
"react-native-drawer-layout": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/react-native-drawer-layout/-/react-native-drawer-layout-1.3.2.tgz",
"integrity": "sha512-fjO0scqbJUfNu2wuEpvywL7DYLXuCXJ2W/zYhWz986rdLytidbys1QGVvkaszHrb4Y7OqO96mTkgpOcP8KWevw==",
"requires": {
"react-native-dismiss-keyboard": "1.0.0"
}
},
"react-native-drawer-layout-polyfill": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/react-native-drawer-layout-polyfill/-/react-native-drawer-layout-polyfill-1.3.2.tgz",
"integrity": "sha512-XzPhfLDJrYHru+e8+dFwhf0FtTeAp7JXPpFYezYV6P1nTeA1Tia/kDpFT+O2DWTrBKBEI8FGhZnThrroZmHIxg==",
"requires": {
"react-native-drawer-layout": "1.3.2"
}
},
"react-native-dropdownalert": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/react-native-dropdownalert/-/react-native-dropdownalert-3.1.2.tgz",
@@ -7012,14 +6980,6 @@
"resolved": "https://registry.npmjs.org/react-native-sqlite-storage/-/react-native-sqlite-storage-3.3.11.tgz",
"integrity": "sha512-Ek2VsteYQKf1Sz8QmWr5MXjyYYcGqVt8i9FFOIrCg/6OboC6MvpdeY/RYWy4PnquHfQirB7unHPagOFZBCo3Zw=="
},
"react-native-tab-view": {
"version": "0.0.70",
"resolved": "https://registry.npmjs.org/react-native-tab-view/-/react-native-tab-view-0.0.70.tgz",
"integrity": "sha512-VOTZs2UCamYrTyBtcxpn4Ko9RkWrq6rZGOY7AagHF/gcCUQBMSWADoplsBopSc5vXnHHeCSR458BkceEuSEaQA==",
"requires": {
"prop-types": "^15.5.10"
}
},
"react-native-vector-icons": {
"version": "6.6.0",
"resolved": "https://registry.npmjs.org/react-native-vector-icons/-/react-native-vector-icons-6.6.0.tgz",
@@ -7166,27 +7126,6 @@
}
}
},
"react-navigation": {
"version": "1.0.0-beta.21",
"resolved": "https://registry.npmjs.org/react-navigation/-/react-navigation-1.0.0-beta.21.tgz",
"integrity": "sha512-bNAiNBtxrumZQmIj6uH2l1jHIkH8mILoGse5BMHOeFWACADl8LnbE91mzAkJ2EbAzAQ5LNpkSjGSIGxbvfsRCw==",
"requires": {
"babel-plugin-transform-define": "^1.3.0",
"clamp": "^1.0.1",
"hoist-non-react-statics": "^2.2.0",
"path-to-regexp": "^1.7.0",
"prop-types": "^15.5.10",
"react-native-drawer-layout-polyfill": "^1.3.2",
"react-native-tab-view": "^0.0.70"
},
"dependencies": {
"hoist-non-react-statics": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.3.1.tgz",
"integrity": "sha1-ND24TGAYxlB3iJgkATWhQg7iLOA="
}
}
},
"react-proxy": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/react-proxy/-/react-proxy-1.1.8.tgz",
@@ -8160,11 +8099,6 @@
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
},
"traverse": {
"version": "0.6.6",
"resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz",
"integrity": "sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc="
},
"trim-right": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",

View File

@@ -12,6 +12,7 @@
"log-android": "adb logcat *:S ReactNative:V ReactNativeJS:V"
},
"dependencies": {
"@react-native-community/push-notification-ios": "^1.0.5",
"@react-native-community/slider": "^2.0.8",
"async-mutex": "^0.1.3",
"base-64": "^0.1.0",