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

View File

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

View File

@ -1,5 +1,6 @@
// @flow // @flow
import { NativeModules } from 'react-native';
import RNCalendarEvents from 'react-native-calendar-events'; import RNCalendarEvents from 'react-native-calendar-events';
import { APP_WILL_MOUNT } from '../app'; import { APP_WILL_MOUNT } from '../app';
@ -123,6 +124,11 @@ function _fetchCalendarEntries(
{ dispatch, getState }, { dispatch, getState },
maybePromptForPermission, maybePromptForPermission,
forcePermission) { forcePermission) {
if (!_isCalendarEnabled()) {
// The calendar feature is not enabled.
return;
}
const state = getState()['features/calendar-sync']; const state = getState()['features/calendar-sync'];
const promptForPermission const promptForPermission
= (maybePromptForPermission && !state.authorization) = (maybePromptForPermission && !state.authorization)
@ -194,6 +200,20 @@ function _getURLFromEvent(event, knownDomains) {
return null; 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 * Retreives the domain name of a room upon join and stores it in the known
* domain list, if not present yet. * domain list, if not present yet.