Просмотр исходного кода

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

master
zbettenbuk 7 лет назад
Родитель
Сommit
56d8210e35
3 измененных файлов: 36 добавлений и 4 удалений
  1. 14
    3
      ios/sdk/src/AppInfo.m
  2. 2
    1
      react/features/app/functions.native.js
  3. 20
    0
      react/features/calendar-sync/middleware.js

+ 14
- 3
ios/sdk/src/AppInfo.m Просмотреть файл

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

+ 2
- 1
react/features/app/functions.native.js Просмотреть файл

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

+ 20
- 0
react/features/calendar-sync/middleware.js Просмотреть файл

1
 // @flow
1
 // @flow
2
 
2
 
3
+import { NativeModules } from 'react-native';
3
 import RNCalendarEvents from 'react-native-calendar-events';
4
 import RNCalendarEvents from 'react-native-calendar-events';
4
 
5
 
5
 import { APP_WILL_MOUNT } from '../app';
6
 import { APP_WILL_MOUNT } from '../app';
123
         { dispatch, getState },
124
         { dispatch, getState },
124
         maybePromptForPermission,
125
         maybePromptForPermission,
125
         forcePermission) {
126
         forcePermission) {
127
+    if (!_isCalendarEnabled()) {
128
+        // The calendar feature is not enabled.
129
+        return;
130
+    }
131
+
126
     const state = getState()['features/calendar-sync'];
132
     const state = getState()['features/calendar-sync'];
127
     const promptForPermission
133
     const promptForPermission
128
         = (maybePromptForPermission && !state.authorization)
134
         = (maybePromptForPermission && !state.authorization)
194
     return null;
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
  * Retreives the domain name of a room upon join and stores it in the known
218
  * Retreives the domain name of a room upon join and stores it in the known
199
  * domain list, if not present yet.
219
  * domain list, if not present yet.

Загрузка…
Отмена
Сохранить