[FIX] iOS Share Extension not loading on development (#4187)

* remove deviceToken from constructor

* remove old patch to verify if is running on shareExtension

* add share extension verification

* Remove imports from `/notifications/` just to test the share extension

* Revert "Remove imports from `/notifications/` just to test the share extension"

This reverts commit b3492abad413a5a8a6cf3cd027e33044c437c627.

* changes from constructor to a plain function

* update pods

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Gleidson Daniel Silva 2022-05-13 11:37:02 -03:00 committed by GitHub
parent 311b346347
commit f99ec9f8e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 128 deletions

View File

@ -3,7 +3,7 @@ import EJSON from 'ejson';
import { store } from '../store/auxStore';
import { deepLinkingOpen } from '../../actions/deepLinking';
import { isFDroidBuild } from '../constants';
import PushNotification from './push';
import { deviceToken, pushNotificationConfigure, setNotificationsBadgeCount } from './push';
import { INotification, SubscriptionType } from '../../definitions';
interface IEjson {
@ -47,11 +47,11 @@ export const onNotification = (push: INotification): void => {
}
};
export const getDeviceToken = (): string => PushNotification.getDeviceToken();
export const setBadgeCount = (count?: number): void => PushNotification.setBadgeCount(count);
export const getDeviceToken = (): string => deviceToken;
export const setBadgeCount = (count?: number): void => setNotificationsBadgeCount(count);
export const initializePushNotifications = (): Promise<INotification> | undefined => {
if (!isFDroidBuild) {
setBadgeCount();
return PushNotification.configure(onNotification);
return pushNotificationConfigure(onNotification);
}
};

View File

@ -13,76 +13,62 @@ import { isIOS } from '../../utils/deviceInfo';
import { store as reduxStore } from '../store/auxStore';
import I18n from '../../i18n';
class PushNotification {
onNotification: (notification: any) => void;
deviceToken: string;
constructor() {
this.onNotification = () => {};
this.deviceToken = '';
if (isIOS) {
// init
Notifications.ios.registerRemoteNotifications();
export let deviceToken = '';
// setCategories
const notificationAction = new NotificationAction('REPLY_ACTION', 'background', I18n.t('Reply'), true, {
buttonTitle: I18n.t('Reply'),
placeholder: I18n.t('Type_message')
});
const notificationCategory = new NotificationCategory('MESSAGE', [notificationAction]);
Notifications.setCategories([notificationCategory]);
export const setNotificationsBadgeCount = (count = 0): void => {
if (isIOS) {
Notifications.ios.setBadgeCount(count);
}
};
export const pushNotificationConfigure = (onNotification: (notification: INotification) => void): Promise<any> => {
if (isIOS) {
// init
Notifications.ios.registerRemoteNotifications();
// setCategories
const notificationAction = new NotificationAction('REPLY_ACTION', 'background', I18n.t('Reply'), true, {
buttonTitle: I18n.t('Reply'),
placeholder: I18n.t('Type_message')
});
const notificationCategory = new NotificationCategory('MESSAGE', [notificationAction]);
Notifications.setCategories([notificationCategory]);
} else {
// init
Notifications.android.registerRemoteNotifications();
}
Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => {
deviceToken = event.deviceToken;
});
Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => {
// TODO: Handle error
console.log(event);
});
Notifications.events().registerNotificationReceivedForeground(
(notification: Notification, completion: (response: NotificationCompletion) => void) => {
completion({ alert: false, sound: false, badge: false });
}
);
Notifications.events().registerNotificationOpened((notification: Notification, completion: () => void) => {
if (isIOS) {
const { background } = reduxStore.getState().app;
if (background) {
onNotification(notification);
}
} else {
// init
Notifications.android.registerRemoteNotifications();
onNotification(notification);
}
completion();
});
Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => {
this.deviceToken = event.deviceToken;
});
Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => {
// TODO: Handle error
console.log(event);
});
Notifications.events().registerNotificationReceivedForeground(
(notification: Notification, completion: (response: NotificationCompletion) => void) => {
completion({ alert: false, sound: false, badge: false });
}
);
Notifications.events().registerNotificationOpened((notification: Notification, completion: () => void) => {
if (isIOS) {
const { background } = reduxStore.getState().app;
if (background) {
this.onNotification(notification);
}
} else {
this.onNotification(notification);
}
completion();
});
Notifications.events().registerNotificationReceivedBackground(
(notification: Notification, completion: (response: any) => void) => {
completion({ alert: true, sound: true, badge: false });
}
);
}
getDeviceToken() {
return this.deviceToken;
}
setBadgeCount = (count = 0) => {
if (isIOS) {
Notifications.ios.setBadgeCount(count);
Notifications.events().registerNotificationReceivedBackground(
(notification: Notification, completion: (response: any) => void) => {
completion({ alert: true, sound: true, badge: false });
}
};
);
configure(onNotification: (notification: INotification) => void): Promise<any> {
this.onNotification = onNotification;
return Notifications.getInitialNotification();
}
}
export default new PushNotification();
return Notifications.getInitialNotification();
};

View File

@ -1,11 +1,11 @@
import { select, takeLatest } from 'redux-saga/effects';
import Push from '../lib/notifications/push';
import log from '../utils/log';
import { localAuthenticate, saveLastLocalAuthenticationSession } from '../utils/localAuthentication';
import { APP_STATE } from '../actions/actionsTypes';
import { RootEnum } from '../definitions';
import { Services } from '../lib/services';
import { setBadgeCount } from '../lib/notifications';
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
const appRoot = yield select(state => state.app.root);
@ -20,7 +20,7 @@ const appHasComeBackToForeground = function* appHasComeBackToForeground() {
try {
yield localAuthenticate(server.server);
Services.checkAndReopen();
Push.setBadgeCount();
setBadgeCount();
return yield Services.setUserPresenceOnline();
} catch (e) {
log(e);

View File

@ -1067,4 +1067,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 9a08139598e951c19d2daf7ac39687272634d547
COCOAPODS: 1.11.2
COCOAPODS: 1.11.3

View File

@ -41,39 +41,3 @@ index f9c858b..94ea188 100644
public abstract class NotificationManagerCompatFacade {
public static NotificationManagerCompat from(@NonNull Context context) {
diff --git a/node_modules/react-native-notifications/lib/ios/RNNotificationCenter.m b/node_modules/react-native-notifications/lib/ios/RNNotificationCenter.m
index 4b33656..36aaa47 100644
--- a/node_modules/react-native-notifications/lib/ios/RNNotificationCenter.m
+++ b/node_modules/react-native-notifications/lib/ios/RNNotificationCenter.m
@@ -29,18 +29,20 @@ - (void)requestPermissions:(NSDictionary *)options {
authOptions = authOptions | UNAuthorizationOptionAnnouncement;
}
}
+ if(![[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"]){
+ [UNUserNotificationCenter.currentNotificationCenter requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
+ if (!error && granted) {
+ [UNUserNotificationCenter.currentNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
+ if (settings.authorizationStatus == UNAuthorizationStatusAuthorized || settings.authorizationStatus == UNAuthorizationStatusProvisional) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
+ });
+ }
+ }];
+ }
+ }];
+ }
- [UNUserNotificationCenter.currentNotificationCenter requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
- if (!error && granted) {
- [UNUserNotificationCenter.currentNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
- if (settings.authorizationStatus == UNAuthorizationStatusAuthorized || settings.authorizationStatus == UNAuthorizationStatusProvisional) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [[UIApplication sharedApplication] registerForRemoteNotifications];
- });
- }
- }];
- }
- }];
}
- (void)setCategories:(NSArray *)json {

View File

@ -4493,7 +4493,7 @@
resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.6.tgz#ed8fc802c45b8e8f54419c2d054e55c9ea344356"
integrity sha512-GRTZLeLJ8ia00ZH8mxMO8t0aC9M1N9bN461Z2eaRurJo6Fpa+utgCwLzI4jQHcrdzuzp5WPN9jRwpsCQ1VhJ5w==
"@types/hoist-non-react-statics@^3.3.0", "@types/hoist-non-react-statics@^3.3.1":
"@types/hoist-non-react-statics@^3.3.1":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==
@ -4694,16 +4694,6 @@
dependencies:
"@types/react" "*"
"@types/react-redux@^7.1.18":
version "7.1.18"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.18.tgz#2bf8fd56ebaae679a90ebffe48ff73717c438e04"
integrity sha512-9iwAsPyJ9DLTRH+OFeIrm9cAbIj1i2ANL3sKQFATqnPWRbg+jEFXyZOKHiQK/N86pNRXbb4HRxAxo0SIX1XwzQ==
dependencies:
"@types/hoist-non-react-statics" "^3.3.0"
"@types/react" "*"
hoist-non-react-statics "^3.3.0"
redux "^4.0.0"
"@types/react-syntax-highlighter@11.0.4":
version "11.0.4"
resolved "https://registry.yarnpkg.com/@types/react-syntax-highlighter/-/react-syntax-highlighter-11.0.4.tgz#d86d17697db62f98046874f62fdb3e53a0bbc4cd"
@ -15452,13 +15442,6 @@ redux@4.2.0:
dependencies:
"@babel/runtime" "^7.9.2"
redux@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.1.0.tgz#eb049679f2f523c379f1aff345c8612f294c88d4"
integrity sha512-uI2dQN43zqLWCt6B/BMGRMY6db7TTY4qeHHfGeKb3EOhmOKjU3KdWvNLJyqaHRksv/ErdNH7cFZWg9jXtewy4g==
dependencies:
"@babel/runtime" "^7.9.2"
redux@^4.0.4:
version "4.0.5"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"