@log-drop/react-native 1.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
10
10
  s.license = package["license"]
11
11
  s.authors = package["author"]
12
12
 
13
- s.platforms = { :ios => min_ios_version_supported }
13
+ s.platforms = { :ios => "15.1" }
14
14
  s.source = { :git => "https://github.com/initialcodess/LogDrop-React-Native-SDK.git", :tag => "#{s.version}" }
15
15
 
16
16
  s.source_files = "ios/**/*.{h,m,mm,swift}"
@@ -22,5 +22,5 @@ if respond_to?(:install_modules_dependencies, true)
22
22
  else
23
23
  s.dependency "React-Core"
24
24
  end
25
- s.dependency 'LogDrop', '1.0.11'
25
+ s.dependency 'LogDrop', '2.0.4'
26
26
  end
@@ -77,6 +77,6 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
77
77
  dependencies {
78
78
  implementation "com.facebook.react:react-android"
79
79
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
80
- implementation "io.logdrop:sdk:1.0.8"
80
+ implementation "io.logdrop:sdk:2.0.3"
81
81
  }
82
82
 
@@ -1,16 +1,37 @@
1
1
  package com.logdropreactnative
2
2
 
3
+ import android.os.Handler
4
+ import android.os.Looper
3
5
  import io.logdrop.sdk.LogDrop
4
6
  import io.logdrop.sdk.LogDropConfig
5
7
 
6
8
  object LogDropReactNative {
9
+ private var lifecycleCallbackRegistered = false
10
+
7
11
  fun initLogDrop(config: LogDropReactNativeConfig) {
8
- LogDrop.init(config.context, LogDropConfig.Builder().apply {
9
- config.apiKey?.let { apiKey(it) }
10
- config.baseUrl?.let { baseUrl(it) }
11
- config.isLoggingEnabled?.let { logcatEnabled(it) }
12
- config.initialIsSDKDisabledValue?.let { initialIsSDKDisabledValue(it) }
13
- frameworkType(config.framework)
14
- }.build())
12
+ val initialize = {
13
+ registerLifecycleCallbackIfNeeded(config)
14
+
15
+ LogDrop.init(config.context, LogDropConfig.Builder().apply {
16
+ config.apiKey?.let { apiKey(it) }
17
+ config.baseUrl?.let { baseUrl(it) }
18
+ config.isLoggingEnabled?.let { logcatEnabled(it) }
19
+ config.initialIsSDKDisabledValue?.let { initialIsSDKDisabledValue(it) }
20
+ frameworkType(config.framework)
21
+ }.build())
22
+ }
23
+
24
+ if (Looper.getMainLooper().isCurrentThread) {
25
+ initialize()
26
+ } else {
27
+ Handler(Looper.getMainLooper()).post(initialize)
28
+ }
29
+ }
30
+
31
+ private fun registerLifecycleCallbackIfNeeded(config: LogDropReactNativeConfig) {
32
+ if (lifecycleCallbackRegistered) return
33
+
34
+ LogDrop.registerActivityLifecycleCallback(config.context.applicationContext)
35
+ lifecycleCallbackRegistered = true
15
36
  }
16
37
  }
@@ -12,6 +12,9 @@ RCT_EXTERN_METHOD(sendLogs)
12
12
  RCT_EXTERN_METHOD(saveCustomCrashReport:(NSString *)threadName
13
13
  stackTrace:(NSString *)stackTrace
14
14
  crashType:(NSString *)crashType)
15
+ RCT_EXTERN_METHOD(requestDemoPermission:(NSString *)permission
16
+ resolver:(RCTPromiseResolveBlock)resolve
17
+ rejecter:(RCTPromiseRejectBlock)reject)
15
18
 
16
19
  + (BOOL)requiresMainQueueSetup
17
20
  {
@@ -1,7 +1,21 @@
1
+ import AVFoundation
2
+ import Contacts
3
+ import CoreLocation
4
+ import EventKit
1
5
  import LogDropSDK
6
+ import Photos
7
+ import React
8
+ import UserNotifications
2
9
 
3
10
  @objc(LogDropReactNative)
4
- class LogDropReactNative: NSObject {
11
+ class LogDropReactNative: NSObject, CLLocationManagerDelegate {
12
+ private let locationManager = CLLocationManager()
13
+ private var pendingLocationResolver: RCTPromiseResolveBlock?
14
+
15
+ override init() {
16
+ super.init()
17
+ locationManager.delegate = self
18
+ }
5
19
 
6
20
  @objc
7
21
  func initLogDrop(_ config: NSDictionary) {
@@ -71,4 +85,175 @@ class LogDropReactNative: NSObject {
71
85
  stackTrace: stackTrace,
72
86
  crashType: crashType)
73
87
  }
88
+
89
+ @objc
90
+ func requestDemoPermission(
91
+ _ permission: String,
92
+ resolver resolve: @escaping RCTPromiseResolveBlock,
93
+ rejecter reject: @escaping RCTPromiseRejectBlock
94
+ ) {
95
+ DispatchQueue.main.async {
96
+ switch permission {
97
+ case "notifications":
98
+ UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in
99
+ UNUserNotificationCenter.current().getNotificationSettings { settings in
100
+ resolve(Self.notificationStatus(settings.authorizationStatus))
101
+ }
102
+ }
103
+ case "location":
104
+ self.pendingLocationResolver = resolve
105
+ self.locationManager.requestWhenInUseAuthorization()
106
+ case "camera":
107
+ AVCaptureDevice.requestAccess(for: .video) { _ in
108
+ resolve(Self.videoStatus(AVCaptureDevice.authorizationStatus(for: .video)))
109
+ }
110
+ case "microphone":
111
+ AVAudioSession.sharedInstance().requestRecordPermission { _ in
112
+ resolve(Self.audioStatus(AVAudioSession.sharedInstance().recordPermission))
113
+ }
114
+ case "contacts":
115
+ CNContactStore().requestAccess(for: .contacts) { _, _ in
116
+ resolve(Self.contactsStatus(CNContactStore.authorizationStatus(for: .contacts)))
117
+ }
118
+ case "calendar":
119
+ let store = EKEventStore()
120
+ if #available(iOS 17.0, *) {
121
+ store.requestFullAccessToEvents { _, _ in
122
+ resolve(Self.calendarStatus(EKEventStore.authorizationStatus(for: .event)))
123
+ }
124
+ } else {
125
+ store.requestAccess(to: .event) { _, _ in
126
+ resolve(Self.calendarStatus(EKEventStore.authorizationStatus(for: .event)))
127
+ }
128
+ }
129
+ case "photos":
130
+ PHPhotoLibrary.requestAuthorization(for: .readWrite) { _ in
131
+ resolve(Self.photoStatus(PHPhotoLibrary.authorizationStatus(for: .readWrite)))
132
+ }
133
+ default:
134
+ reject("unsupported_permission", "Unsupported demo permission: \(permission)", nil)
135
+ }
136
+ }
137
+ }
138
+
139
+ func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
140
+ pendingLocationResolver?(Self.locationStatus(CLLocationManager.authorizationStatus()))
141
+ pendingLocationResolver = nil
142
+ }
143
+
144
+ private static func notificationStatus(_ status: UNAuthorizationStatus) -> String {
145
+ switch status {
146
+ case .authorized, .provisional, .ephemeral:
147
+ return "granted"
148
+ case .denied:
149
+ return "denied"
150
+ case .notDetermined:
151
+ return "not_determined"
152
+ @unknown default:
153
+ return "restricted"
154
+ }
155
+ }
156
+
157
+ private static func locationStatus(_ status: CLAuthorizationStatus) -> String {
158
+ switch status {
159
+ case .authorizedAlways, .authorizedWhenInUse:
160
+ return "granted"
161
+ case .denied:
162
+ return "denied"
163
+ case .notDetermined:
164
+ return "not_determined"
165
+ case .restricted:
166
+ return "restricted"
167
+ @unknown default:
168
+ return "restricted"
169
+ }
170
+ }
171
+
172
+ private static func videoStatus(_ status: AVAuthorizationStatus) -> String {
173
+ switch status {
174
+ case .authorized:
175
+ return "granted"
176
+ case .denied:
177
+ return "denied"
178
+ case .notDetermined:
179
+ return "not_determined"
180
+ case .restricted:
181
+ return "restricted"
182
+ @unknown default:
183
+ return "restricted"
184
+ }
185
+ }
186
+
187
+ private static func audioStatus(_ status: AVAudioSession.RecordPermission) -> String {
188
+ switch status {
189
+ case .granted:
190
+ return "granted"
191
+ case .denied:
192
+ return "denied"
193
+ case .undetermined:
194
+ return "not_determined"
195
+ @unknown default:
196
+ return "restricted"
197
+ }
198
+ }
199
+
200
+ private static func contactsStatus(_ status: CNAuthorizationStatus) -> String {
201
+ switch status {
202
+ case .authorized:
203
+ return "granted"
204
+ case .denied:
205
+ return "denied"
206
+ case .notDetermined:
207
+ return "not_determined"
208
+ case .restricted:
209
+ return "restricted"
210
+ @unknown default:
211
+ return "restricted"
212
+ }
213
+ }
214
+
215
+ private static func calendarStatus(_ status: EKAuthorizationStatus) -> String {
216
+ if #available(iOS 17.0, *) {
217
+ switch status {
218
+ case .fullAccess, .writeOnly:
219
+ return "granted"
220
+ case .denied:
221
+ return "denied"
222
+ case .notDetermined:
223
+ return "not_determined"
224
+ case .restricted:
225
+ return "restricted"
226
+ @unknown default:
227
+ return "restricted"
228
+ }
229
+ }
230
+
231
+ switch status {
232
+ case .authorized:
233
+ return "granted"
234
+ case .denied:
235
+ return "denied"
236
+ case .notDetermined:
237
+ return "not_determined"
238
+ case .restricted:
239
+ return "restricted"
240
+ @unknown default:
241
+ return "restricted"
242
+ }
243
+ }
244
+
245
+ private static func photoStatus(_ status: PHAuthorizationStatus) -> String {
246
+ switch status {
247
+ case .authorized, .limited:
248
+ return "granted"
249
+ case .denied:
250
+ return "denied"
251
+ case .notDetermined:
252
+ return "not_determined"
253
+ case .restricted:
254
+ return "restricted"
255
+ @unknown default:
256
+ return "restricted"
257
+ }
258
+ }
74
259
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@log-drop/react-native",
3
- "version": "1.0.4",
3
+ "version": "2.0.0",
4
4
  "description": "LogDrop React Native SDK",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",