Procházet zdrojové kódy

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

master
zbettenbuk před 7 roky
rodič
revize
56d8210e35

+ 14
- 3
ios/sdk/src/AppInfo.m Zobrazit soubor

@@ -29,8 +29,13 @@ RCT_EXPORT_MODULE();
29 29
 - (NSDictionary *)constantsToExport {
30 30
     NSDictionary<NSString *, id> *infoDictionary
31 31
         = [[NSBundle mainBundle] infoDictionary];
32
+
33
+    // calendarEnabled
34
+    BOOL calendarEnabled
35
+        = infoDictionary[@"NSCalendarsUsageDescription"] != nil;
36
+
37
+    // name
32 38
     NSString *name = infoDictionary[@"CFBundleDisplayName"];
33
-    NSString *version = infoDictionary[@"CFBundleShortVersionString"];
34 39
 
35 40
     if (name == nil) {
36 41
         name = infoDictionary[@"CFBundleName"];
@@ -38,6 +43,13 @@ RCT_EXPORT_MODULE();
38 43
             name = @"";
39 44
         }
40 45
     }
46
+
47
+    // sdkBundlePath
48
+    NSString *sdkBundlePath = [[NSBundle bundleForClass:self.class] bundlePath];
49
+
50
+    // version
51
+    NSString *version = infoDictionary[@"CFBundleShortVersionString"];
52
+
41 53
     if (version == nil) {
42 54
         version = infoDictionary[@"CFBundleVersion"];
43 55
         if (version == nil) {
@@ -45,9 +57,8 @@ RCT_EXPORT_MODULE();
45 57
         }
46 58
     }
47 59
 
48
-    NSString *sdkBundlePath = [[NSBundle bundleForClass:self.class] bundlePath];
49
-
50 60
     return @{
61
+        @"calendarEnabled": [NSNumber numberWithBool:calendarEnabled],
51 62
         @"name": name,
52 63
         @"sdkBundlePath": sdkBundlePath,
53 64
         @"version": version

+ 2
- 1
react/features/app/functions.native.js Zobrazit soubor

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

+ 20
- 0
react/features/calendar-sync/middleware.js Zobrazit soubor

@@ -1,5 +1,6 @@
1 1
 // @flow
2 2
 
3
+import { NativeModules } from 'react-native';
3 4
 import RNCalendarEvents from 'react-native-calendar-events';
4 5
 
5 6
 import { APP_WILL_MOUNT } from '../app';
@@ -123,6 +124,11 @@ function _fetchCalendarEntries(
123 124
         { dispatch, getState },
124 125
         maybePromptForPermission,
125 126
         forcePermission) {
127
+    if (!_isCalendarEnabled()) {
128
+        // The calendar feature is not enabled.
129
+        return;
130
+    }
131
+
126 132
     const state = getState()['features/calendar-sync'];
127 133
     const promptForPermission
128 134
         = (maybePromptForPermission && !state.authorization)
@@ -194,6 +200,20 @@ function _getURLFromEvent(event, knownDomains) {
194 200
     return null;
195 201
 }
196 202
 
203
+/**
204
+ * Determines whether the calendar feature is enabled by the app. For
205
+ * example, Apple through its App Store requires NSCalendarsUsageDescription in
206
+ * the app's Info.plist or App Store rejects the app.
207
+ *
208
+ * @returns {boolean} If the app has enabled the calendar feature, {@code true};
209
+ * otherwise, {@code false}.
210
+ */
211
+export function _isCalendarEnabled() {
212
+    const { calendarEnabled } = NativeModules.AppInfo;
213
+
214
+    return typeof calendarEnabled === 'undefined' ? true : calendarEnabled;
215
+}
216
+
197 217
 /**
198 218
  * Retreives the domain name of a room upon join and stores it in the known
199 219
  * domain list, if not present yet.

Načítá se…
Zrušit
Uložit