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

View File

@ -13,16 +13,18 @@ import { isIOS } from '../../utils/deviceInfo';
import { store as reduxStore } from '../store/auxStore'; import { store as reduxStore } from '../store/auxStore';
import I18n from '../../i18n'; import I18n from '../../i18n';
class PushNotification { export let deviceToken = '';
onNotification: (notification: any) => void;
deviceToken: string; export const setNotificationsBadgeCount = (count = 0): void => {
constructor() { if (isIOS) {
this.onNotification = () => {}; Notifications.ios.setBadgeCount(count);
this.deviceToken = ''; }
};
export const pushNotificationConfigure = (onNotification: (notification: INotification) => void): Promise<any> => {
if (isIOS) { if (isIOS) {
// init // init
Notifications.ios.registerRemoteNotifications(); Notifications.ios.registerRemoteNotifications();
// setCategories // setCategories
const notificationAction = new NotificationAction('REPLY_ACTION', 'background', I18n.t('Reply'), true, { const notificationAction = new NotificationAction('REPLY_ACTION', 'background', I18n.t('Reply'), true, {
buttonTitle: I18n.t('Reply'), buttonTitle: I18n.t('Reply'),
@ -36,7 +38,7 @@ class PushNotification {
} }
Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => { Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => {
this.deviceToken = event.deviceToken; deviceToken = event.deviceToken;
}); });
Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => { Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => {
@ -54,10 +56,10 @@ class PushNotification {
if (isIOS) { if (isIOS) {
const { background } = reduxStore.getState().app; const { background } = reduxStore.getState().app;
if (background) { if (background) {
this.onNotification(notification); onNotification(notification);
} }
} else { } else {
this.onNotification(notification); onNotification(notification);
} }
completion(); completion();
}); });
@ -67,22 +69,6 @@ class PushNotification {
completion({ alert: true, sound: true, badge: false }); completion({ alert: true, sound: true, badge: false });
} }
); );
}
getDeviceToken() {
return this.deviceToken;
}
setBadgeCount = (count = 0) => {
if (isIOS) {
Notifications.ios.setBadgeCount(count);
}
};
configure(onNotification: (notification: INotification) => void): Promise<any> {
this.onNotification = onNotification;
return Notifications.getInitialNotification(); return Notifications.getInitialNotification();
} };
}
export default new PushNotification();

View File

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

View File

@ -1067,4 +1067,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 9a08139598e951c19d2daf7ac39687272634d547 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 abstract class NotificationManagerCompatFacade {
public static NotificationManagerCompat from(@NonNull Context context) { 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" resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.6.tgz#ed8fc802c45b8e8f54419c2d054e55c9ea344356"
integrity sha512-GRTZLeLJ8ia00ZH8mxMO8t0aC9M1N9bN461Z2eaRurJo6Fpa+utgCwLzI4jQHcrdzuzp5WPN9jRwpsCQ1VhJ5w== 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" version "3.3.1"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f" resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA== integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==
@ -4694,16 +4694,6 @@
dependencies: dependencies:
"@types/react" "*" "@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": "@types/react-syntax-highlighter@11.0.4":
version "11.0.4" version "11.0.4"
resolved "https://registry.yarnpkg.com/@types/react-syntax-highlighter/-/react-syntax-highlighter-11.0.4.tgz#d86d17697db62f98046874f62fdb3e53a0bbc4cd" 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: dependencies:
"@babel/runtime" "^7.9.2" "@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: redux@^4.0.4:
version "4.0.5" version "4.0.5"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f" resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"