Skip to content

Commit 91ea920

Browse files
author
karimK3
authored
Merge pull request #4 from TheBubblesCompany/harmonize-ios-android
Harmonize iOS and Android.
2 parents 71f918c + 2e01172 commit 91ea920

23 files changed

+438
-130
lines changed

android/src/main/AndroidManifest.xml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1+
<manifest
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.reactlibrary">
14

2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.reactlibrary">
5+
6+
<!-- /!\ = Dangerous permission, need Runtime Permission with Android 6.0+ -->
7+
8+
9+
<!-- BLE | Start -->
10+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- BL use need this with Android 6.0+ --> <!-- /!\ -->
11+
<uses-permission android:name="android.permission.BLUETOOTH"/> <!-- BL use need this -->
12+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <!-- BL scan need this -->
13+
<!-- BLE | End -->
14+
15+
16+
<!-- Internet | Start -->
17+
<uses-permission android:name="android.permission.INTERNET"/> <!-- Need this to call WebServices -->
18+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
19+
<!-- Internet | End -->
20+
21+
22+
<!-- Get IMEI | Start -->
23+
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> <!-- Need this to access the IMEI --> <!-- /!\ -->
24+
<!-- Get IMEI | End -->
425

526
</manifest>
627

android/src/main/java/com/reactlibrary/RNBubblesReactBridgeModule.java

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import android.os.Build.VERSION;
99
import android.os.Build.VERSION_CODES;
1010
import android.support.v4.app.ActivityCompat;
11-
import com.facebook.react.bridge.Arguments;
11+
import android.util.Log;
1212
import com.facebook.react.bridge.Callback;
1313
import com.facebook.react.bridge.ReactApplicationContext;
1414
import com.facebook.react.bridge.ReactContextBaseJavaModule;
@@ -41,7 +41,7 @@
4141

4242
public class RNBubblesReactBridgeModule extends ReactContextBaseJavaModule {
4343

44-
private static final String TAG = "BubblesReactBridge";
44+
private static final String TAG = "RNBubblesReactBridge";
4545

4646
private static String DEFAULT_SUCCESS_HANDLER_RETURN = null;
4747
private static String DEFAULT_FAILED_HANDLER_RETURN = null;
@@ -57,11 +57,13 @@ public class RNBubblesReactBridgeModule extends ReactContextBaseJavaModule {
5757
}
5858
}
5959

60-
private static final int CALLBACK_CODE_JSON_EXCEPTION = 0;
61-
private static final int CALLBACK_CODE_UNKNOWN_SERVICE = 1;
62-
private static final int CALLBACK_CODE_BRIDGE_VERSION = 2;
63-
private static final int CALLBACK_CODE_BLUETOOTH_ERROR = 3;
64-
private static final int CALLBACK_CODE_BLUETOOTH_ON = 4;
60+
private static final String CALLBACK_CODE_JSON_EXCEPTION = "JSON_EXCEPTION";
61+
private static final String CALLBACK_CODE_UNKNOWN_SERVICE = "UNKNOWN_SERVICE";
62+
private static final String CALLBACK_CODE_BRIDGE_VERSION = "UNKNOWN_BRIDGE_VERSION";
63+
private static final String CALLBACK_CODE_BLUETOOTH_ERROR = "BLUETOOTH_ERROR";
64+
private static final String CALLBACK_CODE_BLUETOOTH_ON = "BLUETOOTH_ON";
65+
private static final String CALLBACK_CODE_PERMISSION_REQUIRED = "PERMISSION_REQUIRED";
66+
private static final String CALLBACK_CODE_INTERNAL_ERROR = "INTERNAL_ERROR";
6567

6668
private final ReactApplicationContext reactContext;
6769

@@ -79,7 +81,7 @@ public RNBubblesReactBridgeModule(ReactApplicationContext reactContext) {
7981

8082
@Override
8183
public String getName() {
82-
return "BubblesReactBridge";
84+
return "RNBubblesReactBridge";
8385
}
8486

8587
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -94,6 +96,7 @@ public void reactIsUpToDate() {
9496
@ReactMethod
9597
public void log(String data) {
9698
ML.e(TAG, data);
99+
Log.e(TAG, data);
97100
}
98101

99102
@ReactMethod
@@ -160,6 +163,71 @@ public void getLocalizationPermissionState(Callback callback) {
160163
}
161164
}
162165

166+
@ReactMethod
167+
public void getDeviceId(Callback callback) {
168+
String deviceID = MyBubblesSDK.mInstance.deviceID;
169+
if (deviceID != null) {
170+
try {
171+
JSONObject result = new JSONObject();
172+
result.put("deviceId", deviceID);
173+
callback.invoke(null, result.toString());
174+
} catch (JSONException e) {
175+
callback.invoke(createRejectCallback(CALLBACK_CODE_JSON_EXCEPTION, e.getMessage()), null);
176+
}
177+
} else {
178+
callback.invoke(createRejectCallback(CALLBACK_CODE_INTERNAL_ERROR, "Is SDK init?"), null);
179+
}
180+
}
181+
182+
@ReactMethod
183+
public void getApplicationId(Callback callback) {
184+
String apiKey = MyBubblesSDK.mInstance.apiKey;
185+
if (apiKey != null) {
186+
try {
187+
JSONObject result = new JSONObject();
188+
result.put("applicationId", apiKey);
189+
callback.invoke(null, result.toString());
190+
} catch (JSONException e) {
191+
callback.invoke(createRejectCallback(CALLBACK_CODE_JSON_EXCEPTION, e.getMessage()), null);
192+
}
193+
} else {
194+
callback.invoke(createRejectCallback(CALLBACK_CODE_INTERNAL_ERROR, "Is SDK init?"), null);
195+
}
196+
}
197+
198+
@ReactMethod
199+
public void getUserId(Callback callback) {
200+
String userID = MyBubblesSDK.mInstance.userID;
201+
if (userID != null) {
202+
try {
203+
JSONObject result = new JSONObject();
204+
result.put("userId", userID);
205+
callback.invoke(null, result.toString());
206+
} catch (JSONException e) {
207+
callback.invoke(createRejectCallback(CALLBACK_CODE_JSON_EXCEPTION, e.getMessage()), null);
208+
}
209+
} else {
210+
callback.invoke(createRejectCallback(CALLBACK_CODE_INTERNAL_ERROR, "Is SDK init?"), null);
211+
}
212+
}
213+
214+
@ReactMethod
215+
public void getUniqueDeviceId(Callback callback) {
216+
String uniqueID = MyBubblesSDK.mInstance.uniqueID;
217+
if (uniqueID != null) {
218+
try {
219+
JSONObject result = new JSONObject();
220+
result.put("isAuthorized", true);
221+
result.put("uniqueDeviceId", uniqueID);
222+
callback.invoke(null, result.toString());
223+
} catch (JSONException e) {
224+
callback.invoke(createRejectCallback(CALLBACK_CODE_JSON_EXCEPTION, e.getMessage()), null);
225+
}
226+
} else {
227+
callback.invoke(createRejectCallback(CALLBACK_CODE_PERMISSION_REQUIRED, "Permission required"), null);
228+
}
229+
}
230+
163231
@ReactMethod
164232
public void askForUniqueIdPermission() {
165233
log("askForUniqueIdPermission");
@@ -359,9 +427,14 @@ public void update(Observable observable, Object data) {
359427
try {
360428

361429
log("onSendUniqueId");
430+
boolean isAuthorized = (Boolean) data;
362431

363432
JSONObject result = new JSONObject();
364-
result.put("isAuthorized", data);
433+
result.put("isAuthorized", isAuthorized);
434+
if (isAuthorized) {
435+
result.put("uniqueDeviceId", MyBubblesSDK.mInstance.uniqueID);
436+
}
437+
365438
sendEvent("onSendUniqueId", result.toString());
366439

367440
} catch (JSONException e) {
@@ -458,7 +531,7 @@ private String createFormattableFailedReturn(final String message) {
458531
return null;
459532
}
460533

461-
private WritableMap createRejectCallback(int code, String message) {
534+
private WritableMap createRejectCallback(String code, String message) {
462535
ErrorObject errorObject = new ErrorObject(code, message);
463536
WritableMap errorMap = null;
464537
try {
@@ -471,10 +544,10 @@ private WritableMap createRejectCallback(int code, String message) {
471544

472545
private class ErrorObject {
473546

474-
private int code;
547+
private String code;
475548
private String message;
476549

477-
public ErrorObject(final int code, final String message) {
550+
public ErrorObject(final String code, final String message) {
478551
this.code = code;
479552
this.message = message;
480553
}

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ function moduleSelector() {
1010
}
1111
return BubblesReactBridgeIOS;
1212
}
13-
1413
const BubblesReactBridge = moduleSelector();
14+
BubblesReactBridge.errorCode = {
15+
PERMISSION_REJECTED: "PERMISSION_REJECTED",
16+
PERMISSION_REQUIRED: "PERMISSION_REQUIRED",
17+
}
1518

1619
export default BubblesReactBridge;

ios/Frameworks/Bubbles.framework/Bubbles

100644100755
1.76 MB
Binary file not shown.

ios/Frameworks/Bubbles.framework/Headers/Bubbles.h

100644100755
File mode changed.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// DataAccess.h
3+
// BubblesTwo
4+
//
5+
// Created by Pierre RACINE on 30/03/2016.
6+
// Copyright © 2016 Absolutlabs. All rights reserved.
7+
//
8+
#import <UIKit/UIKit.h>
9+
#import <CoreLocation/CoreLocation.h>
10+
11+
#define DATA [DataAccess dataAccess]
12+
13+
@class CLLocation;
14+
15+
@interface DataAccess : NSObject
16+
17+
+ (DataAccess *) dataAccess;
18+
19+
20+
@property BOOL debug;
21+
@property (nonatomic, strong) CLLocationManager * locationManager;
22+
@property (nonatomic, strong) NSString * latitude;
23+
@property (nonatomic, strong) NSString * longitude;
24+
25+
//Header Parameters
26+
27+
@property (nonatomic) NSInteger apiVersion;
28+
@property (nonatomic, strong) NSString * apiKey;
29+
@property (nonatomic, strong) NSString * deviceId;
30+
@property (nonatomic, strong) NSString * userId;
31+
@property (nonatomic, strong) NSString * uniqueId;
32+
@property (nonatomic, strong) NSString * applicationLanguage;
33+
34+
@property (nonatomic) BOOL bluetoothEnable;
35+
36+
37+
#pragma mark - Request
38+
39+
- (void) requestDeviceId;
40+
41+
- (void) getAPIkey:(NSString*)apiKey andUserId:(NSString*)userID;
42+
43+
- (void) requestServices;
44+
45+
- (void) confirmLocalization;
46+
- (void) confirmNotification;
47+
48+
49+
-(void)requestPOSTWithUrl:(NSString *)stringURL andDictionaryPost:(NSDictionary *)dictionaryPost
50+
success:(void (^)(NSURLSessionDataTask * sessionDataTask, id response))success
51+
failure:(void (^)(NSURLSessionDataTask * sessionDataTask, NSString *error))failure;
52+
53+
-(void)requestGETWithUrl:(NSString *)stringURL andDictionaryPost:(NSDictionary *)dictionaryPost
54+
success:(void (^)(NSURLSessionDataTask * sessionDataTask, id response))success
55+
failure:(void (^)(NSURLSessionDataTask * sessionDataTask, NSString *error))failure;
56+
57+
-(void)requestPUTWithUrl:(NSString *)stringURL andDictionaryPost:(NSDictionary *)dictionaryPost
58+
success:(void (^)(NSURLSessionDataTask * sessionDataTask, id response))success
59+
failure:(void (^)(NSURLSessionDataTask * sessionDataTask, NSString *error))failure;
60+
61+
62+
63+
64+
@end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-10 Bytes
Binary file not shown.

ios/Frameworks/Bubbles.framework/Modules/module.modulemap

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)