1import { AndroidConfig, ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';
2
3const pkg = require('expo-background-fetch/package.json');
4
5const withBackgroundFetch: ConfigPlugin = config => {
6  if (!config.ios) config.ios = {};
7  if (!config.ios.infoPlist) config.ios.infoPlist = {};
8  if (!config.ios.infoPlist.UIBackgroundModes) config.ios.infoPlist.UIBackgroundModes = [];
9
10  // TODO: Maybe entitlements are needed
11  config.ios.infoPlist.UIBackgroundModes = [
12    ...new Set(config.ios.infoPlist.UIBackgroundModes.concat(['location', 'fetch'])),
13  ];
14
15  return AndroidConfig.Permissions.withPermissions(config, [
16    'android.permission.RECEIVE_BOOT_COMPLETED',
17    'android.permission.WAKE_LOCK',
18  ]);
19};
20
21export default createRunOncePlugin(withBackgroundFetch, pkg.name, pkg.version);
22