Add ability to detect calendar permission description in the plist file (iOS)

This commit is contained in:
zbettenbuk 2018-04-13 23:00:54 +02:00 committed by Lyubo Marinov
parent f1ab160c62
commit 56d8210e35
3 changed files with 36 additions and 4 deletions

View File

@ -29,8 +29,13 @@ RCT_EXPORT_MODULE();
- (NSDictionary *)constantsToExport {
NSDictionary<NSString *, id> *infoDictionary
= [[NSBundle mainBundle] infoDictionary];
// calendarEnabled
BOOL calendarEnabled
= infoDictionary[@"NSCalendarsUsageDescription"] != nil;
// name
NSString *name = infoDictionary[@"CFBundleDisplayName"];
NSString *version = infoDictionary[@"CFBundleShortVersionString"];
if (name == nil) {
name = infoDictionary[@"CFBundleName"];
@ -38,6 +43,13 @@ RCT_EXPORT_MODULE();
name = @"";
}
}
// sdkBundlePath
NSString *sdkBundlePath = [[NSBundle bundleForClass:self.class] bundlePath];
// version
NSString *version = infoDictionary[@"CFBundleShortVersionString"];
if (version == nil) {
version = infoDictionary[@"CFBundleVersion"];
if (version == nil) {
@ -45,9 +57,8 @@ RCT_EXPORT_MODULE();
}
}
NSString *sdkBundlePath = [[NSBundle bundleForClass:self.class] bundlePath];
return @{
@"calendarEnabled": [NSNumber numberWithBool:calendarEnabled],
@"name": name,
@"sdkBundlePath": sdkBundlePath,
@"version": version

View File

@ -1,4 +1,5 @@
/* @flow */
// @flow
import { NativeModules } from 'react-native';
export * from './getRouteToRender';

View File

@ -1,5 +1,6 @@
// @flow
import { NativeModules } from 'react-native';
import RNCalendarEvents from 'react-native-calendar-events';
import { APP_WILL_MOUNT } from '../app';
@ -123,6 +124,11 @@ function _fetchCalendarEntries(
{ dispatch, getState },
maybePromptForPermission,
forcePermission) {
if (!_isCalendarEnabled()) {
// The calendar feature is not enabled.
return;
}
const state = getState()['features/calendar-sync'];
const promptForPermission
= (maybePromptForPermission && !state.authorization)
@ -194,6 +200,20 @@ function _getURLFromEvent(event, knownDomains) {
return null;
}
/**
* Determines whether the calendar feature is enabled by the app. For
* example, Apple through its App Store requires NSCalendarsUsageDescription in
* the app's Info.plist or App Store rejects the app.
*
* @returns {boolean} If the app has enabled the calendar feature, {@code true};
* otherwise, {@code false}.
*/
export function _isCalendarEnabled() {
const { calendarEnabled } = NativeModules.AppInfo;
return typeof calendarEnabled === 'undefined' ? true : calendarEnabled;
}
/**
* Retreives the domain name of a room upon join and stores it in the known
* domain list, if not present yet.