react-native-mytatva-rn-sdk 1.2.36 → 1.2.38

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.
@@ -0,0 +1,294 @@
1
+ //
2
+ // MyReactNativeBridge.m
3
+ // example
4
+ //
5
+ // Created by The Coding Studio on 19/05/25.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import "MyReactNativeBridge.h"
10
+ #import <UIKit/UIKit.h>
11
+ #import <React/RCTEventDispatcher.h>
12
+ #import <React/RCTEventEmitter.h>
13
+ #import "react_native_mytatva_rn_sdk-Swift.h"
14
+
15
+ #import <React/RCTBridgeModule.h>
16
+ #import <React/RCTEventEmitter.h>
17
+ @implementation MyEventEmitterManager
18
+
19
+ RCT_EXPORT_MODULE();
20
+
21
+ // Define the supported events
22
+ - (NSArray<NSString *> *)supportedEvents {
23
+ return @[@"cgmDeviceEvent"]; // Event names to listen to in JS
24
+ }
25
+
26
+ // Example method to emit an event from native to JS
27
+ RCT_EXPORT_METHOD(emitEvent:(NSString *)message) {
28
+ // Send an event with the name "EventName" and a message payload
29
+ [self sendEventWithName:@"cgmDeviceEvent" body:@{@"status": message}];
30
+ }
31
+
32
+ @end
33
+ UIViewController *globalAttachTransmitterVC = nil;
34
+
35
+ @implementation CgmTrackyLib
36
+
37
+ RCT_EXPORT_MODULE();
38
+
39
+ // This method returns the list of events the module supports
40
+ - (NSArray<NSString *> *)supportedEvents
41
+ {
42
+ return @[@"cgmDeviceEvent"];
43
+ }
44
+
45
+ // Start listening for notifications
46
+ - (instancetype)init
47
+ {
48
+ if (self = [super init]) {
49
+ // Add observer for the notification from UIViewController
50
+ [[NSNotificationCenter defaultCenter] addObserver:self
51
+ selector:@selector(handleNotification:)
52
+ name:@"cgmDeviceEvent"
53
+ object:nil];
54
+ }
55
+ return self;
56
+ }
57
+
58
+
59
+ // Handle the incoming notification and emit the event to React Native
60
+ - (void)handleNotification:(NSNotification *)notification
61
+ {
62
+ // Extract data from the notification
63
+ NSDictionary *userInfo = notification.userInfo;
64
+
65
+ // Send the data to React Native via event emitter
66
+ [self sendEventWithName:@"cgmDeviceEvent" body:@{@"status": @"WARM_PERIOD_STARTED"}];
67
+ }
68
+
69
+ // Private helper
70
+ - (void)observeTransmitterUnbindStatusInternal:(NSString *)token
71
+ response:(NSDictionary *)responseDict
72
+ completion:(void (^)(NSDictionary *response, NSError *error))completion;
73
+ {
74
+ // Save token
75
+ [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"authToken"];
76
+ [[NSUserDefaults standardUserDefaults] synchronize];
77
+
78
+ // Save CGM status item to UserDefaults (if needed by Swift)
79
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:responseDict options:0 error:nil];
80
+ if (jsonData) {
81
+ [[NSUserDefaults standardUserDefaults] setObject:jsonData forKey:@"CGMStatusItem"];
82
+ [[NSUserDefaults standardUserDefaults] synchronize];
83
+ }
84
+
85
+ // Call Swift method which reads CGMStatusItem from UserDefaults
86
+ FinalViewModelManager *manager = [FinalViewModelManager shared];
87
+ [manager callForObserveTransmitterUnbindStatusWithCompletion:^(NSDictionary *response, NSError *error) {
88
+ if (completion) {
89
+ completion(response, error);
90
+ }
91
+ }];
92
+ }
93
+
94
+ // Clean up the observer when the module is deallocated
95
+ - (void)dealloc
96
+ {
97
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
98
+ }
99
+
100
+
101
+ RCT_EXPORT_METHOD(startCgmTracky:(NSString *)token)
102
+ {
103
+ // NSLog(@"Received token: %@", token);
104
+ //
105
+ // // Save token
106
+ // [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"authToken"];
107
+ // [[NSUserDefaults standardUserDefaults] synchronize];
108
+ //
109
+ //
110
+ // // Show native view
111
+ // dispatch_async(dispatch_get_main_queue(), ^{
112
+ // UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
113
+ // UIViewController *rootVC = keyWindow.rootViewController;
114
+ //
115
+ // UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainCGM" bundle:nil];
116
+ // UIViewController *nativeVC = [storyboard instantiateViewControllerWithIdentifier:@"StartConnectionViewController"];
117
+ //
118
+ // if (nativeVC) {
119
+ // UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:nativeVC];
120
+ // navController.modalPresentationStyle = UIModalPresentationOverFullScreen;
121
+ // [rootVC presentViewController:navController animated:YES completion:nil];
122
+ // }
123
+ // });
124
+
125
+ NSLog(@"Received token: %@", token);
126
+
127
+ [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"authToken"];
128
+ [[NSUserDefaults standardUserDefaults] synchronize];
129
+ dispatch_async(dispatch_get_main_queue(), ^{
130
+ UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
131
+ UIViewController *rootVC = keyWindow.rootViewController;
132
+ // Load the storyboard
133
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainCGM" bundle:[NSBundle mainBundle]];
134
+
135
+ // Instantiate the target ViewController
136
+ UIViewController *reconnectVC = [storyboard instantiateViewControllerWithIdentifier:@"StartConnectionViewController"];
137
+
138
+ // Set presentation style
139
+ reconnectVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
140
+ // Set isForReconnect = YES
141
+ if ([reconnectVC respondsToSelector:@selector(setIsForReconnect:)]) {
142
+ [reconnectVC setValue:@(YES) forKey:@"isForReconnect"];
143
+ }
144
+ // Present it directly without navigation
145
+ // if (reconnectVC) {
146
+ // [rootVC presentViewController:reconnectVC animated:YES completion:nil];
147
+ // }
148
+
149
+ UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:reconnectVC];
150
+ navController.modalPresentationStyle = UIModalPresentationOverFullScreen;
151
+ if (reconnectVC) {
152
+ [rootVC presentViewController:navController animated:YES completion:nil];
153
+ }
154
+ });
155
+ }
156
+
157
+
158
+
159
+ RCT_EXPORT_METHOD(reconnectCgmTracky:(NSString *)token)
160
+ {
161
+ NSLog(@"Received token: %@", token);
162
+
163
+ [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"authToken"];
164
+ [[NSUserDefaults standardUserDefaults] synchronize];
165
+ dispatch_async(dispatch_get_main_queue(), ^{
166
+ UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
167
+ UIViewController *rootVC = keyWindow.rootViewController;
168
+ // Load the storyboard
169
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainCGM" bundle:[NSBundle mainBundle]];
170
+
171
+ // Instantiate the target ViewController
172
+ UIViewController *reconnectVC = [storyboard instantiateViewControllerWithIdentifier:@"StartConnectionViewController"];
173
+
174
+ // Set presentation style
175
+ reconnectVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
176
+ // Set isForReconnect = YES
177
+ if ([reconnectVC respondsToSelector:@selector(setIsForReconnect:)]) {
178
+ [reconnectVC setValue:@(YES) forKey:@"isForReconnect"];
179
+ }
180
+ // Present it directly without navigation
181
+ // if (reconnectVC) {
182
+ // [rootVC presentViewController:reconnectVC animated:YES completion:nil];
183
+ // }
184
+
185
+ UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:reconnectVC];
186
+ navController.modalPresentationStyle = UIModalPresentationOverFullScreen;
187
+ if (reconnectVC) {
188
+ [rootVC presentViewController:navController animated:YES completion:nil];
189
+ }
190
+ });
191
+ }
192
+
193
+
194
+ RCT_EXPORT_METHOD(openHelpSupport)
195
+ {
196
+ dispatch_async(dispatch_get_main_queue(), ^{
197
+ UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
198
+ UIViewController *rootVC = keyWindow.rootViewController;
199
+
200
+ // Load the storyboard
201
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainCGM" bundle:nil];
202
+
203
+ // Instantiate the target ViewController
204
+ UIViewController *chatWithExpertVC = [storyboard instantiateViewControllerWithIdentifier:@"ChatWithExpertViewController"];
205
+ if ([chatWithExpertVC respondsToSelector:@selector(setIsOnlyThis:)]) {
206
+ [chatWithExpertVC setValue:@(YES) forKey:@"isOnlyThis"];
207
+ }
208
+ // Set presentation style
209
+ chatWithExpertVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
210
+
211
+ // Present it directly without navigation
212
+ if (chatWithExpertVC) {
213
+ [rootVC presentViewController:chatWithExpertVC animated:YES completion:nil];
214
+ }
215
+ });
216
+ }
217
+
218
+ RCT_EXPORT_METHOD(observeAllGlucoseData:(NSString *)token)
219
+ {
220
+ NSLog(@"Received token: %@", token);
221
+
222
+ FinalViewModelManager *manager = [FinalViewModelManager shared];
223
+ [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"authToken"];
224
+ [[NSUserDefaults standardUserDefaults] synchronize];
225
+
226
+ dispatch_async(dispatch_get_main_queue(), ^{
227
+ UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
228
+ UIViewController *rootVC = keyWindow.rootViewController;
229
+
230
+ // Load the storyboard
231
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainCGM" bundle:nil];
232
+
233
+ // Instantiate the target ViewController
234
+ globalAttachTransmitterVC = [storyboard instantiateViewControllerWithIdentifier:@"AttachTransmitterViewController"];
235
+
236
+ // Set presentation style
237
+ // chatWithExpertVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
238
+
239
+ // Present it directly without navigation
240
+ //if (chatWithExpertVC) {
241
+ // [rootVC presentViewController:chatWithExpertVC animated:YES completion:nil];
242
+ // }
243
+ });
244
+ }
245
+
246
+ //RCT_EXPORT_METHOD(observeTransmitterUnbindStatus:(NSString *)token)
247
+ //{
248
+ // NSLog(@"Received token: %@", token);
249
+ // [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"authToken"];
250
+ // [[NSUserDefaults standardUserDefaults] synchronize];
251
+ // FinalViewModelManager *manager = [FinalViewModelManager shared];
252
+ // [manager callForObserveTransmitterUnbindStatus];
253
+ //}
254
+
255
+ RCT_EXPORT_METHOD(observeTransmitterUnbindStatus:(NSString *)token response:(NSString *)responseJsonString)
256
+ {
257
+ // Optional: Parse the JSON string if needed
258
+ NSData *jsonData = [responseJsonString dataUsingEncoding:NSUTF8StringEncoding];
259
+ NSError *jsonError;
260
+ NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError];
261
+
262
+ if (jsonError) {
263
+ NSLog(@"Failed to parse JSON: %@", jsonError.localizedDescription);
264
+ [self sendEventWithName:@"observeTransmitterUnbindStatusHandler" body:@{
265
+ @"token": token ?: @"",
266
+ @"success": @NO,
267
+ @"error": @"Invalid JSON response from JS"
268
+ }];
269
+ return;
270
+ }
271
+
272
+ // Now you have responseDict, you can use it
273
+ [self observeTransmitterUnbindStatusInternal:token response:responseDict completion:^(NSDictionary *response, NSError *error) {
274
+ if (error) {
275
+ NSDictionary *errorPayload = @{
276
+ @"token": token ?: @"",
277
+ @"success": @NO,
278
+ @"error": error.localizedDescription ?: @"Unknown error"
279
+ };
280
+ [self sendEventWithName:@"observeTransmitterUnbindStatusHandler" body:errorPayload];
281
+ } else {
282
+ NSDictionary *successPayload = @{
283
+ @"token": token ?: @"",
284
+ @"responseFromBackend": response ?: @{},
285
+ @"responseFromJS": responseDict ?: @{},
286
+ @"success": @YES
287
+ };
288
+ [self sendEventWithName:@"observeTransmitterUnbindStatusHandler" body:successPayload];
289
+ }
290
+ }];
291
+
292
+ }
293
+
294
+ @end
@@ -0,0 +1,31 @@
1
+ //
2
+ // VideoTVC.swift
3
+ // MyTatvaCare
4
+ //
5
+ // Created by Nirav Ramani on 08/05/25.
6
+ //
7
+
8
+ import UIKit
9
+
10
+ class VideoTVC: UITableViewCell {
11
+
12
+ @IBOutlet weak var imageViewBackground: UIImageView!
13
+ @IBOutlet weak var imageViewPlay: UIImageView!
14
+ @IBOutlet weak var buttonPlay: UIButton!
15
+
16
+ var onPlayVideo: (() -> Void)?
17
+
18
+ override func awakeFromNib() {
19
+ super.awakeFromNib()
20
+ // Initialization code
21
+ imageViewPlay.loadGif(named: "play")
22
+ imageViewBackground.contentMode = .scaleAspectFill
23
+ buttonPlay.addTarget(self, action: #selector(playButtonTapped), for: .touchUpInside)
24
+ }
25
+
26
+ @objc func playButtonTapped() {
27
+ onPlayVideo?()
28
+ }
29
+
30
+
31
+ }