Skip to content

Commit

Permalink
Merge pull request #3 from OneSignal/plugin-improvements
Browse files Browse the repository at this point in the history
iOS Improvements
  • Loading branch information
rgomezp authored Oct 26, 2021
2 parents 52ccd7e + 6806136 commit 573c267
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions onesignal/withOneSignalIos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
ConfigPlugin,
withEntitlementsPlist,
withInfoPlist,
} from '@expo/config-plugins';
import { OneSignalPluginProps } from './withOneSignal';
} from "@expo/config-plugins";
import { OneSignalPluginProps } from "./withOneSignal";

// ---------- ---------- ---------- ----------

Expand All @@ -18,10 +18,10 @@ import { OneSignalPluginProps } from './withOneSignal';
*/
const withAppEnvironment: ConfigPlugin<OneSignalPluginProps> = (
config,
{ mode },
{ mode }
) => {
return withEntitlementsPlist(config, (newConfig) => {
newConfig.modResults['aps-environment'] = mode;
newConfig.modResults["aps-environment"] = mode;
return newConfig;
});
};
Expand All @@ -31,13 +31,19 @@ const withAppEnvironment: ConfigPlugin<OneSignalPluginProps> = (
* @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
*/
const withRemoteNotificationsPermissions: ConfigPlugin<OneSignalPluginProps> = (
config,
config
) => {
const BACKGROUND_MODE_KEYS = ["external-accessory", "remote-notification"];
return withInfoPlist(config, (newConfig) => {
newConfig.modResults.UIBackgroundModes = [
'external-accessory',
'remote-notifications',
];
if (!Array.isArray(newConfig.modResults.UIBackgroundModes)) {
newConfig.modResults.UIBackgroundModes = [];
}
for (const key of BACKGROUND_MODE_KEYS) {
if (!newConfig.modResults.UIBackgroundModes.includes(key)) {
newConfig.modResults.UIBackgroundModes.push(key);
}
}

return newConfig;
});
};
Expand All @@ -47,20 +53,25 @@ const withRemoteNotificationsPermissions: ConfigPlugin<OneSignalPluginProps> = (
* @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps (step 4.4)
*/
const withAppGroupPermissions: ConfigPlugin<OneSignalPluginProps> = (
config,
config
) => {
const APP_GROUP_KEY = "com.apple.security.application-groups";
return withEntitlementsPlist(config, (newConfig) => {
newConfig.modResults['com.apple.security.application-groups'] = [
`group.${newConfig?.ios?.bundleIdentifier || ''}.onesignal`,
];
if (!Array.isArray(newConfig.modResults[APP_GROUP_KEY])) {
newConfig.modResults[APP_GROUP_KEY] = [];
}
(newConfig.modResults[APP_GROUP_KEY] as Array<any>).push(
`group.${newConfig?.ios?.bundleIdentifier || ""}.onesignal`
);

return newConfig;
});
};

// ---------- ---------- ---------- ----------
export const withOneSignalIos: ConfigPlugin<OneSignalPluginProps> = (
config,
props,
props
) => {
withAppEnvironment(config, props);
withRemoteNotificationsPermissions(config, props);
Expand Down

0 comments on commit 573c267

Please sign in to comment.