소스 검색

[RN] Add AppInfo module

It provides access to the app's display name and version.
j8
Saúl Ibarra Corretgé 7 년 전
부모
커밋
3fdffa7497

+ 56
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/AppInfoModule.java 파일 보기

@@ -0,0 +1,56 @@
1
+package org.jitsi.meet.sdk;
2
+
3
+import android.content.Context;
4
+import android.content.pm.ApplicationInfo;
5
+import android.content.pm.PackageInfo;
6
+import android.content.pm.PackageManager;
7
+
8
+import com.facebook.react.bridge.ReactApplicationContext;
9
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
10
+
11
+import java.util.HashMap;
12
+import java.util.Map;
13
+
14
+class AppInfoModule extends ReactContextBaseJavaModule {
15
+    /**
16
+     * React Native module name.
17
+     */
18
+    private static final String MODULE_NAME = "AppInfo";
19
+
20
+    public AppInfoModule(ReactApplicationContext reactContext) {
21
+        super(reactContext);
22
+    }
23
+
24
+    /**
25
+     * Gets a mapping with the constants this module is exporting.
26
+     *
27
+     * @return a {@link Map} mapping the constants to be exported with their
28
+     * values.
29
+     */
30
+    @Override
31
+    public Map<String, Object> getConstants() {
32
+        Map<String, Object> constants = new HashMap<>();
33
+        Context context = getReactApplicationContext();
34
+        PackageManager pm = context.getPackageManager();
35
+        ApplicationInfo appInfo;
36
+        PackageInfo packageInfo;
37
+
38
+        try {
39
+             appInfo = pm.getApplicationInfo(context.getPackageName(), 0);
40
+             packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
41
+        } catch (PackageManager.NameNotFoundException e) {
42
+            constants.put("name", "");
43
+            constants.put("version", "");
44
+            return constants;
45
+        }
46
+
47
+        constants.put("name", pm.getApplicationLabel(appInfo));
48
+        constants.put("version", packageInfo.versionName);
49
+        return constants;
50
+    }
51
+
52
+    @Override
53
+    public String getName() {
54
+        return MODULE_NAME;
55
+    }
56
+}

+ 1
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java 파일 보기

@@ -61,6 +61,7 @@ public class JitsiMeetView extends FrameLayout {
61 61
             ReactApplicationContext reactContext) {
62 62
         return Arrays.<NativeModule>asList(
63 63
             new AndroidSettingsModule(reactContext),
64
+            new AppInfoModule(reactContext),
64 65
             new AudioModeModule(reactContext),
65 66
             new ExternalAPIModule(reactContext),
66 67
             new ProximityModule(reactContext)

+ 4
- 0
ios/sdk/sdk.xcodeproj/project.pbxproj 파일 보기

@@ -14,6 +14,7 @@
14 14
 		0B93EF7E1EC9DDCD0030D24D /* RCTBridgeWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 0B93EF7C1EC9DDCD0030D24D /* RCTBridgeWrapper.h */; };
15 15
 		0B93EF7F1EC9DDCD0030D24D /* RCTBridgeWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B93EF7D1EC9DDCD0030D24D /* RCTBridgeWrapper.m */; };
16 16
 		0BA13D311EE83FF8007BEF7F /* ExternalAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BA13D301EE83FF8007BEF7F /* ExternalAPI.m */; };
17
+		0BB9AD7D1F60356D001C08DB /* AppInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BB9AD7C1F60356D001C08DB /* AppInfo.m */; };
17 18
 		0BCA495F1EC4B6C600B793EE /* AudioMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BCA495C1EC4B6C600B793EE /* AudioMode.m */; };
18 19
 		0BCA49601EC4B6C600B793EE /* POSIX.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BCA495D1EC4B6C600B793EE /* POSIX.m */; };
19 20
 		0BCA49611EC4B6C600B793EE /* Proximity.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BCA495E1EC4B6C600B793EE /* Proximity.m */; };
@@ -31,6 +32,7 @@
31 32
 		0B93EF7C1EC9DDCD0030D24D /* RCTBridgeWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBridgeWrapper.h; sourceTree = "<group>"; };
32 33
 		0B93EF7D1EC9DDCD0030D24D /* RCTBridgeWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTBridgeWrapper.m; sourceTree = "<group>"; };
33 34
 		0BA13D301EE83FF8007BEF7F /* ExternalAPI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExternalAPI.m; sourceTree = "<group>"; };
35
+		0BB9AD7C1F60356D001C08DB /* AppInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppInfo.m; sourceTree = "<group>"; };
34 36
 		0BCA495C1EC4B6C600B793EE /* AudioMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioMode.m; sourceTree = "<group>"; };
35 37
 		0BCA495D1EC4B6C600B793EE /* POSIX.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = POSIX.m; sourceTree = "<group>"; };
36 38
 		0BCA495E1EC4B6C600B793EE /* Proximity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Proximity.m; sourceTree = "<group>"; };
@@ -87,6 +89,7 @@
87 89
 			isa = PBXGroup;
88 90
 			children = (
89 91
 				0BCA495C1EC4B6C600B793EE /* AudioMode.m */,
92
+				0BB9AD7C1F60356D001C08DB /* AppInfo.m */,
90 93
 				0BA13D301EE83FF8007BEF7F /* ExternalAPI.m */,
91 94
 				0BD906E91EC0C00300C8C18E /* Info.plist */,
92 95
 				0BD906E81EC0C00300C8C18E /* JitsiMeet.h */,
@@ -253,6 +256,7 @@
253 256
 			isa = PBXSourcesBuildPhase;
254 257
 			buildActionMask = 2147483647;
255 258
 			files = (
259
+				0BB9AD7D1F60356D001C08DB /* AppInfo.m in Sources */,
256 260
 				0B93EF7F1EC9DDCD0030D24D /* RCTBridgeWrapper.m in Sources */,
257 261
 				0BA13D311EE83FF8007BEF7F /* ExternalAPI.m in Sources */,
258 262
 				0BCA49601EC4B6C600B793EE /* POSIX.m in Sources */,

+ 42
- 0
ios/sdk/src/AppInfo.m 파일 보기

@@ -0,0 +1,42 @@
1
+/*
2
+ * Copyright @ 2017-present Atlassian Pty Ltd
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+#import "RCTBridgeModule.h"
18
+#import "RCTLog.h"
19
+
20
+#import <AVFoundation/AVFoundation.h>
21
+
22
+@interface AppInfo : NSObject<RCTBridgeModule>
23
+@end
24
+
25
+@implementation AppInfo
26
+
27
+RCT_EXPORT_MODULE();
28
+
29
+- (NSDictionary *)constantsToExport {
30
+    NSString *name = [[[NSBundle mainBundle]infoDictionary]objectForKey :@"CFBundleDisplayName"];
31
+    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
32
+    if (version == nil) {
33
+        version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
34
+        if (version == nil) {
35
+            version = @"";
36
+        }
37
+    }
38
+
39
+    return @{ @"name" : name, @"version" : version };
40
+};
41
+
42
+@end

Loading…
취소
저장