feeddo-react-native 0.0.0-stage → 0.1.1
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.
- package/LICENSE +21 -0
- package/README.md +401 -2
- package/android/build.gradle +39 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/dev/feeddo/reactnative/FeeddoReactNativeModule.java +380 -0
- package/android/src/main/java/dev/feeddo/reactnative/FeeddoReactNativePackage.java +25 -0
- package/dist/Feeddo.d.ts +131 -0
- package/dist/Feeddo.d.ts.map +1 -0
- package/dist/Feeddo.js +176 -0
- package/dist/Feeddo.js.map +1 -0
- package/dist/FeeddoClient.d.ts +151 -0
- package/dist/FeeddoClient.d.ts.map +1 -0
- package/dist/FeeddoClient.js +690 -0
- package/dist/FeeddoClient.js.map +1 -0
- package/dist/FeeddoProvider.d.ts +23 -0
- package/dist/FeeddoProvider.d.ts.map +1 -0
- package/dist/FeeddoProvider.js +76 -0
- package/dist/FeeddoProvider.js.map +1 -0
- package/dist/config/FeeddoConfig.d.ts +10 -0
- package/dist/config/FeeddoConfig.d.ts.map +1 -0
- package/dist/config/FeeddoConfig.js +10 -0
- package/dist/config/FeeddoConfig.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/models/Conversation.d.ts +27 -0
- package/dist/models/Conversation.d.ts.map +1 -0
- package/dist/models/Conversation.js +24 -0
- package/dist/models/Conversation.js.map +1 -0
- package/dist/models/EndUser.d.ts +49 -0
- package/dist/models/EndUser.d.ts.map +1 -0
- package/dist/models/EndUser.js +2 -0
- package/dist/models/EndUser.js.map +1 -0
- package/dist/models/FeeddoNotification.d.ts +15 -0
- package/dist/models/FeeddoNotification.d.ts.map +1 -0
- package/dist/models/FeeddoNotification.js +15 -0
- package/dist/models/FeeddoNotification.js.map +1 -0
- package/dist/models/HomeData.d.ts +16 -0
- package/dist/models/HomeData.d.ts.map +1 -0
- package/dist/models/HomeData.js +19 -0
- package/dist/models/HomeData.js.map +1 -0
- package/dist/models/Message.d.ts +12 -0
- package/dist/models/Message.d.ts.map +1 -0
- package/dist/models/Message.js +25 -0
- package/dist/models/Message.js.map +1 -0
- package/dist/models/PushProvider.d.ts +14 -0
- package/dist/models/PushProvider.d.ts.map +1 -0
- package/dist/models/PushProvider.js +9 -0
- package/dist/models/PushProvider.js.map +1 -0
- package/dist/models/Task.d.ts +17 -0
- package/dist/models/Task.d.ts.map +1 -0
- package/dist/models/Task.js +22 -0
- package/dist/models/Task.js.map +1 -0
- package/dist/models/TaskComment.d.ts +11 -0
- package/dist/models/TaskComment.d.ts.map +1 -0
- package/dist/models/TaskComment.js +27 -0
- package/dist/models/TaskComment.js.map +1 -0
- package/dist/models/Ticket.d.ts +13 -0
- package/dist/models/Ticket.d.ts.map +1 -0
- package/dist/models/Ticket.js +14 -0
- package/dist/models/Ticket.js.map +1 -0
- package/dist/native/FeeddoNative.d.ts +58 -0
- package/dist/native/FeeddoNative.d.ts.map +1 -0
- package/dist/native/FeeddoNative.js +22 -0
- package/dist/native/FeeddoNative.js.map +1 -0
- package/dist/push/FeeddoPushNotificationApns.d.ts +73 -0
- package/dist/push/FeeddoPushNotificationApns.d.ts.map +1 -0
- package/dist/push/FeeddoPushNotificationApns.js +301 -0
- package/dist/push/FeeddoPushNotificationApns.js.map +1 -0
- package/dist/services/ApiService.d.ts +64 -0
- package/dist/services/ApiService.d.ts.map +1 -0
- package/dist/services/ApiService.js +406 -0
- package/dist/services/ApiService.js.map +1 -0
- package/dist/services/ConversationService.d.ts +45 -0
- package/dist/services/ConversationService.d.ts.map +1 -0
- package/dist/services/ConversationService.js +259 -0
- package/dist/services/ConversationService.js.map +1 -0
- package/dist/services/WebSocketService.d.ts +26 -0
- package/dist/services/WebSocketService.d.ts.map +1 -0
- package/dist/services/WebSocketService.js +157 -0
- package/dist/services/WebSocketService.js.map +1 -0
- package/dist/theme/FeeddoTheme.d.ts +31 -0
- package/dist/theme/FeeddoTheme.d.ts.map +1 -0
- package/dist/theme/FeeddoTheme.js +60 -0
- package/dist/theme/FeeddoTheme.js.map +1 -0
- package/dist/ui/FeeddoFeedbackCard.d.ts +15 -0
- package/dist/ui/FeeddoFeedbackCard.d.ts.map +1 -0
- package/dist/ui/FeeddoFeedbackCard.js +188 -0
- package/dist/ui/FeeddoFeedbackCard.js.map +1 -0
- package/dist/ui/FeeddoModal.d.ts +20 -0
- package/dist/ui/FeeddoModal.d.ts.map +1 -0
- package/dist/ui/FeeddoModal.js +180 -0
- package/dist/ui/FeeddoModal.js.map +1 -0
- package/dist/ui/components/AttachmentPreview.d.ts +10 -0
- package/dist/ui/components/AttachmentPreview.d.ts.map +1 -0
- package/dist/ui/components/AttachmentPreview.js +143 -0
- package/dist/ui/components/AttachmentPreview.js.map +1 -0
- package/dist/ui/components/ChatInputArea.d.ts +16 -0
- package/dist/ui/components/ChatInputArea.d.ts.map +1 -0
- package/dist/ui/components/ChatInputArea.js +85 -0
- package/dist/ui/components/ChatInputArea.js.map +1 -0
- package/dist/ui/components/FeeddoIcon.d.ts +10 -0
- package/dist/ui/components/FeeddoIcon.d.ts.map +1 -0
- package/dist/ui/components/FeeddoIcon.js +690 -0
- package/dist/ui/components/FeeddoIcon.js.map +1 -0
- package/dist/ui/components/FeeddoNotificationBadge.d.ts +14 -0
- package/dist/ui/components/FeeddoNotificationBadge.d.ts.map +1 -0
- package/dist/ui/components/FeeddoNotificationBadge.js +171 -0
- package/dist/ui/components/FeeddoNotificationBadge.js.map +1 -0
- package/dist/ui/components/MessageBubble.d.ts +13 -0
- package/dist/ui/components/MessageBubble.d.ts.map +1 -0
- package/dist/ui/components/MessageBubble.js +163 -0
- package/dist/ui/components/MessageBubble.js.map +1 -0
- package/dist/ui/components/NotificationsSheet.d.ts +10 -0
- package/dist/ui/components/NotificationsSheet.d.ts.map +1 -0
- package/dist/ui/components/NotificationsSheet.js +252 -0
- package/dist/ui/components/NotificationsSheet.js.map +1 -0
- package/dist/ui/components/RatingWidget.d.ts +11 -0
- package/dist/ui/components/RatingWidget.d.ts.map +1 -0
- package/dist/ui/components/RatingWidget.js +34 -0
- package/dist/ui/components/RatingWidget.js.map +1 -0
- package/dist/ui/components/TaskCard.d.ts +12 -0
- package/dist/ui/components/TaskCard.d.ts.map +1 -0
- package/dist/ui/components/TaskCard.js +210 -0
- package/dist/ui/components/TaskCard.js.map +1 -0
- package/dist/ui/components/TaskDetailsSheet.d.ts +15 -0
- package/dist/ui/components/TaskDetailsSheet.d.ts.map +1 -0
- package/dist/ui/components/TaskDetailsSheet.js +577 -0
- package/dist/ui/components/TaskDetailsSheet.js.map +1 -0
- package/dist/ui/components/TicketCard.d.ts +11 -0
- package/dist/ui/components/TicketCard.d.ts.map +1 -0
- package/dist/ui/components/TicketCard.js +100 -0
- package/dist/ui/components/TicketCard.js.map +1 -0
- package/dist/ui/components/TicketDetailsSheet.d.ts +14 -0
- package/dist/ui/components/TicketDetailsSheet.d.ts.map +1 -0
- package/dist/ui/components/TicketDetailsSheet.js +254 -0
- package/dist/ui/components/TicketDetailsSheet.js.map +1 -0
- package/dist/ui/components/TypingIndicator.d.ts +10 -0
- package/dist/ui/components/TypingIndicator.d.ts.map +1 -0
- package/dist/ui/components/TypingIndicator.js +77 -0
- package/dist/ui/components/TypingIndicator.js.map +1 -0
- package/dist/ui/screens/FeeddoChatScreen.d.ts +13 -0
- package/dist/ui/screens/FeeddoChatScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoChatScreen.js +681 -0
- package/dist/ui/screens/FeeddoChatScreen.js.map +1 -0
- package/dist/ui/screens/FeeddoHomeScreen.d.ts +15 -0
- package/dist/ui/screens/FeeddoHomeScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoHomeScreen.js +653 -0
- package/dist/ui/screens/FeeddoHomeScreen.js.map +1 -0
- package/dist/ui/screens/FeeddoMessagesScreen.d.ts +12 -0
- package/dist/ui/screens/FeeddoMessagesScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoMessagesScreen.js +326 -0
- package/dist/ui/screens/FeeddoMessagesScreen.js.map +1 -0
- package/dist/ui/screens/FeeddoTasksScreen.d.ts +13 -0
- package/dist/ui/screens/FeeddoTasksScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoTasksScreen.js +517 -0
- package/dist/ui/screens/FeeddoTasksScreen.js.map +1 -0
- package/dist/ui/screens/FeeddoTicketsScreen.d.ts +10 -0
- package/dist/ui/screens/FeeddoTicketsScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoTicketsScreen.js +112 -0
- package/dist/ui/screens/FeeddoTicketsScreen.js.map +1 -0
- package/dist/utils/DeviceInfoHelper.d.ts +29 -0
- package/dist/utils/DeviceInfoHelper.d.ts.map +1 -0
- package/dist/utils/DeviceInfoHelper.js +190 -0
- package/dist/utils/DeviceInfoHelper.js.map +1 -0
- package/dist/utils/MediaHelper.d.ts +20 -0
- package/dist/utils/MediaHelper.d.ts.map +1 -0
- package/dist/utils/MediaHelper.js +92 -0
- package/dist/utils/MediaHelper.js.map +1 -0
- package/dist/utils/NotificationSupport.d.ts +22 -0
- package/dist/utils/NotificationSupport.d.ts.map +1 -0
- package/dist/utils/NotificationSupport.js +211 -0
- package/dist/utils/NotificationSupport.js.map +1 -0
- package/dist/utils/StorageHelper.d.ts +65 -0
- package/dist/utils/StorageHelper.d.ts.map +1 -0
- package/dist/utils/StorageHelper.js +273 -0
- package/dist/utils/StorageHelper.js.map +1 -0
- package/feeddo-react-native.podspec +26 -0
- package/ios/FeeddoReactNativeModule.h +8 -0
- package/ios/FeeddoReactNativeModule.m +831 -0
- package/package.json +56 -4
- package/src/Feeddo.ts +247 -0
- package/src/FeeddoClient.ts +895 -0
- package/src/FeeddoProvider.tsx +139 -0
- package/src/config/FeeddoConfig.ts +9 -0
- package/src/index.ts +67 -0
- package/src/models/Conversation.ts +50 -0
- package/src/models/EndUser.ts +65 -0
- package/src/models/FeeddoNotification.ts +29 -0
- package/src/models/HomeData.ts +33 -0
- package/src/models/Message.ts +36 -0
- package/src/models/PushProvider.ts +15 -0
- package/src/models/Task.ts +40 -0
- package/src/models/TaskComment.ts +36 -0
- package/src/models/Ticket.ts +25 -0
- package/src/native/FeeddoNative.ts +80 -0
- package/src/push/FeeddoPushNotificationApns.ts +362 -0
- package/src/services/ApiService.ts +456 -0
- package/src/services/ConversationService.ts +305 -0
- package/src/services/WebSocketService.ts +185 -0
- package/src/theme/FeeddoTheme.ts +85 -0
- package/src/ui/FeeddoFeedbackCard.tsx +245 -0
- package/src/ui/FeeddoModal.tsx +309 -0
- package/src/ui/components/AttachmentPreview.tsx +192 -0
- package/src/ui/components/ChatInputArea.tsx +154 -0
- package/src/ui/components/FeeddoIcon.tsx +903 -0
- package/src/ui/components/FeeddoNotificationBadge.tsx +234 -0
- package/src/ui/components/MessageBubble.tsx +223 -0
- package/src/ui/components/NotificationsSheet.tsx +324 -0
- package/src/ui/components/RatingWidget.tsx +64 -0
- package/src/ui/components/TaskCard.tsx +259 -0
- package/src/ui/components/TaskDetailsSheet.tsx +747 -0
- package/src/ui/components/TicketCard.tsx +128 -0
- package/src/ui/components/TicketDetailsSheet.tsx +324 -0
- package/src/ui/components/TypingIndicator.tsx +104 -0
- package/src/ui/screens/FeeddoChatScreen.tsx +877 -0
- package/src/ui/screens/FeeddoHomeScreen.tsx +824 -0
- package/src/ui/screens/FeeddoMessagesScreen.tsx +414 -0
- package/src/ui/screens/FeeddoTasksScreen.tsx +671 -0
- package/src/ui/screens/FeeddoTicketsScreen.tsx +164 -0
- package/src/utils/DeviceInfoHelper.ts +209 -0
- package/src/utils/MediaHelper.ts +105 -0
- package/src/utils/NotificationSupport.ts +233 -0
- package/src/utils/StorageHelper.ts +305 -0
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
#import "FeeddoReactNativeModule.h"
|
|
2
|
+
|
|
3
|
+
#import <UIKit/UIKit.h>
|
|
4
|
+
#import <AVKit/AVKit.h>
|
|
5
|
+
#import <AVFoundation/AVFoundation.h>
|
|
6
|
+
#import <UserNotifications/UserNotifications.h>
|
|
7
|
+
#import <objc/runtime.h>
|
|
8
|
+
|
|
9
|
+
#if __has_include(<PhotosUI/PhotosUI.h>)
|
|
10
|
+
#import <PhotosUI/PhotosUI.h>
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
#if __has_include(<UniformTypeIdentifiers/UniformTypeIdentifiers.h>)
|
|
14
|
+
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
#import <MobileCoreServices/MobileCoreServices.h>
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Helper: Find top-most UIViewController (works over RN Modals)
|
|
21
|
+
// ============================================================================
|
|
22
|
+
static UIViewController *FeeddoTopViewController(void) {
|
|
23
|
+
UIWindow *keyWindow = nil;
|
|
24
|
+
if (@available(iOS 13.0, *)) {
|
|
25
|
+
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
|
|
26
|
+
if (scene.activationState == UISceneActivationStateForegroundActive &&
|
|
27
|
+
[scene isKindOfClass:[UIWindowScene class]]) {
|
|
28
|
+
UIWindowScene *windowScene = (UIWindowScene *)scene;
|
|
29
|
+
for (UIWindow *win in windowScene.windows) {
|
|
30
|
+
if (win.isKeyWindow) {
|
|
31
|
+
keyWindow = win;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!keyWindow && windowScene.windows.count > 0) {
|
|
36
|
+
keyWindow = windowScene.windows.firstObject;
|
|
37
|
+
}
|
|
38
|
+
if (keyWindow) break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!keyWindow) {
|
|
43
|
+
#pragma clang diagnostic push
|
|
44
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
45
|
+
keyWindow = UIApplication.sharedApplication.keyWindow;
|
|
46
|
+
#pragma clang diagnostic pop
|
|
47
|
+
}
|
|
48
|
+
UIViewController *top = keyWindow.rootViewController;
|
|
49
|
+
while (top.presentedViewController && !top.presentedViewController.isBeingDismissed) {
|
|
50
|
+
top = top.presentedViewController;
|
|
51
|
+
}
|
|
52
|
+
return top;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Helper: APNs Payload Normalization (matches Flutter & iOS SDKs)
|
|
57
|
+
// ============================================================================
|
|
58
|
+
static id FeeddoSanitizeJsonValue(id value) {
|
|
59
|
+
if (!value || [value isKindOfClass:[NSNull class]]) {
|
|
60
|
+
return nil;
|
|
61
|
+
}
|
|
62
|
+
if ([value isKindOfClass:[NSString class]] ||
|
|
63
|
+
[value isKindOfClass:[NSNumber class]]) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
if ([value isKindOfClass:[NSArray class]]) {
|
|
67
|
+
NSMutableArray *arr = [NSMutableArray array];
|
|
68
|
+
for (id item in (NSArray *)value) {
|
|
69
|
+
id sanitized = FeeddoSanitizeJsonValue(item);
|
|
70
|
+
if (sanitized) [arr addObject:sanitized];
|
|
71
|
+
}
|
|
72
|
+
return arr;
|
|
73
|
+
}
|
|
74
|
+
if ([value isKindOfClass:[NSDictionary class]]) {
|
|
75
|
+
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
|
76
|
+
[(NSDictionary *)value enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
77
|
+
if ([key isKindOfClass:[NSString class]]) {
|
|
78
|
+
id sanitized = FeeddoSanitizeJsonValue(obj);
|
|
79
|
+
if (sanitized) dict[key] = sanitized;
|
|
80
|
+
}
|
|
81
|
+
}];
|
|
82
|
+
return dict;
|
|
83
|
+
}
|
|
84
|
+
return [value description];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static NSDictionary *FeeddoNormalizeNotificationPayload(NSDictionary *userInfo) {
|
|
88
|
+
NSMutableDictionary *normalized = [NSMutableDictionary dictionary];
|
|
89
|
+
if (!userInfo) return normalized;
|
|
90
|
+
|
|
91
|
+
// 1. Nested data (dictionary or JSON string)
|
|
92
|
+
id rawData = userInfo[@"data"];
|
|
93
|
+
if ([rawData isKindOfClass:[NSDictionary class]]) {
|
|
94
|
+
[(NSDictionary *)rawData enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
95
|
+
if ([key isKindOfClass:[NSString class]]) {
|
|
96
|
+
id sanitized = FeeddoSanitizeJsonValue(obj);
|
|
97
|
+
if (sanitized) normalized[key] = sanitized;
|
|
98
|
+
}
|
|
99
|
+
}];
|
|
100
|
+
} else if ([rawData isKindOfClass:[NSString class]]) {
|
|
101
|
+
NSData *jsonData = [(NSString *)rawData dataUsingEncoding:NSUTF8StringEncoding];
|
|
102
|
+
if (jsonData) {
|
|
103
|
+
id parsed = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
|
104
|
+
if ([parsed isKindOfClass:[NSDictionary class]]) {
|
|
105
|
+
[(NSDictionary *)parsed enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
106
|
+
if ([key isKindOfClass:[NSString class]]) {
|
|
107
|
+
id sanitized = FeeddoSanitizeJsonValue(obj);
|
|
108
|
+
if (sanitized) normalized[key] = sanitized;
|
|
109
|
+
}
|
|
110
|
+
}];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 2. Top-level keys excluding aps and data
|
|
116
|
+
[userInfo enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
117
|
+
if (![key isKindOfClass:[NSString class]]) return;
|
|
118
|
+
NSString *keyStr = (NSString *)key;
|
|
119
|
+
if ([keyStr isEqualToString:@"aps"] || [keyStr isEqualToString:@"data"]) return;
|
|
120
|
+
if (!normalized[keyStr]) {
|
|
121
|
+
id sanitized = FeeddoSanitizeJsonValue(obj);
|
|
122
|
+
if (sanitized) normalized[keyStr] = sanitized;
|
|
123
|
+
}
|
|
124
|
+
}];
|
|
125
|
+
|
|
126
|
+
// 3. Extract title, body, and badge from aps
|
|
127
|
+
NSDictionary *aps = [userInfo[@"aps"] isKindOfClass:[NSDictionary class]] ? userInfo[@"aps"] : nil;
|
|
128
|
+
if (aps) {
|
|
129
|
+
id alert = aps[@"alert"];
|
|
130
|
+
if ([alert isKindOfClass:[NSDictionary class]]) {
|
|
131
|
+
NSString *title = alert[@"title"];
|
|
132
|
+
if ([title isKindOfClass:[NSString class]] && title.length > 0 && !normalized[@"title"]) {
|
|
133
|
+
normalized[@"title"] = title;
|
|
134
|
+
}
|
|
135
|
+
NSString *body = alert[@"body"];
|
|
136
|
+
if ([body isKindOfClass:[NSString class]] && body.length > 0 && !normalized[@"body"]) {
|
|
137
|
+
normalized[@"body"] = body;
|
|
138
|
+
}
|
|
139
|
+
} else if ([alert isKindOfClass:[NSString class]] && ((NSString *)alert).length > 0 && !normalized[@"body"]) {
|
|
140
|
+
normalized[@"body"] = alert;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
id badge = aps[@"badge"];
|
|
144
|
+
if (badge && ![badge isKindOfClass:[NSNull class]] && !normalized[@"badge"]) {
|
|
145
|
+
id sanitized = FeeddoSanitizeJsonValue(badge);
|
|
146
|
+
if (sanitized) normalized[@"badge"] = sanitized;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return normalized;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ============================================================================
|
|
154
|
+
// FeeddoReactNativeModule: DeviceInfo + Image Picker + Video Player
|
|
155
|
+
// ============================================================================
|
|
156
|
+
@interface FeeddoReactNativeModule () <
|
|
157
|
+
UIImagePickerControllerDelegate,
|
|
158
|
+
UINavigationControllerDelegate,
|
|
159
|
+
UIAdaptivePresentationControllerDelegate
|
|
160
|
+
#if __has_include(<PhotosUI/PhotosUI.h>)
|
|
161
|
+
, PHPickerViewControllerDelegate
|
|
162
|
+
#endif
|
|
163
|
+
>
|
|
164
|
+
@property (nonatomic, copy, nullable) RCTPromiseResolveBlock pendingPickResolve;
|
|
165
|
+
@property (nonatomic, copy, nullable) RCTPromiseRejectBlock pendingPickReject;
|
|
166
|
+
@end
|
|
167
|
+
|
|
168
|
+
@implementation FeeddoReactNativeModule
|
|
169
|
+
|
|
170
|
+
RCT_EXPORT_MODULE(FeeddoReactNative);
|
|
171
|
+
|
|
172
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
173
|
+
return NO;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
RCT_EXPORT_METHOD(getDeviceInfo:(RCTPromiseResolveBlock)resolve
|
|
177
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
178
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
179
|
+
UIDevice *device = [UIDevice currentDevice];
|
|
180
|
+
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
|
|
181
|
+
NSString *appVersion = infoDict[@"CFBundleShortVersionString"];
|
|
182
|
+
NSString *appBuild = infoDict[@"CFBundleVersion"];
|
|
183
|
+
NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
|
|
184
|
+
NSLocale *locale = [NSLocale currentLocale];
|
|
185
|
+
NSString *localeId = [locale localeIdentifier];
|
|
186
|
+
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
|
|
187
|
+
|
|
188
|
+
NSMutableDictionary *result = [NSMutableDictionary dictionary];
|
|
189
|
+
result[@"platform"] = @"ios";
|
|
190
|
+
result[@"deviceModel"] = device.model ?: @"iOS";
|
|
191
|
+
result[@"osVersion"] = [NSString stringWithFormat:@"%@ %@", device.systemName ?: @"iOS", device.systemVersion ?: @""];
|
|
192
|
+
if (appVersion) result[@"appVersion"] = appVersion;
|
|
193
|
+
if (appBuild) result[@"appBuildNumber"] = appBuild;
|
|
194
|
+
if (bundleId) result[@"packageName"] = bundleId;
|
|
195
|
+
if (localeId) result[@"locale"] = localeId;
|
|
196
|
+
if (countryCode) result[@"countryCode"] = countryCode;
|
|
197
|
+
|
|
198
|
+
resolve(result);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
RCT_EXPORT_METHOD(pickImage:(RCTPromiseResolveBlock)resolve
|
|
203
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
204
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
205
|
+
if (self.pendingPickResolve) {
|
|
206
|
+
self.pendingPickResolve([NSNull null]);
|
|
207
|
+
self.pendingPickResolve = nil;
|
|
208
|
+
self.pendingPickReject = nil;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
UIViewController *topVC = FeeddoTopViewController();
|
|
212
|
+
if (!topVC) {
|
|
213
|
+
reject(@"no_view_controller", @"Unable to find active view controller", nil);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
self.pendingPickResolve = resolve;
|
|
218
|
+
self.pendingPickReject = reject;
|
|
219
|
+
|
|
220
|
+
if (@available(iOS 14.0, *)) {
|
|
221
|
+
PHPickerConfiguration *config = [[PHPickerConfiguration alloc] init];
|
|
222
|
+
config.selectionLimit = 1;
|
|
223
|
+
config.filter = [PHPickerFilter imagesFilter];
|
|
224
|
+
|
|
225
|
+
PHPickerViewController *picker = [[PHPickerViewController alloc] initWithConfiguration:config];
|
|
226
|
+
picker.delegate = self;
|
|
227
|
+
picker.presentationController.delegate = self;
|
|
228
|
+
[topVC presentViewController:picker animated:YES completion:nil];
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
|
|
233
|
+
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
|
|
234
|
+
#pragma clang diagnostic push
|
|
235
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
236
|
+
imagePicker.mediaTypes = @[(NSString *)kUTTypeImage];
|
|
237
|
+
#pragma clang diagnostic pop
|
|
238
|
+
imagePicker.delegate = self;
|
|
239
|
+
imagePicker.presentationController.delegate = self;
|
|
240
|
+
[topVC presentViewController:imagePicker animated:YES completion:nil];
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
RCT_EXPORT_METHOD(openVideoPlayer:(NSString *)urlString
|
|
245
|
+
headers:(NSDictionary *)headers
|
|
246
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
247
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
248
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
249
|
+
NSURL *url = [NSURL URLWithString:urlString];
|
|
250
|
+
if (!url) {
|
|
251
|
+
reject(@"invalid_url", @"Invalid video URL", nil);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
UIViewController *topVC = FeeddoTopViewController();
|
|
256
|
+
if (!topVC) {
|
|
257
|
+
reject(@"no_view_controller", @"Unable to find active view controller", nil);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
NSDictionary *options = headers && headers.count > 0
|
|
262
|
+
? @{ @"AVURLAssetHTTPHeaderFieldsKey": headers }
|
|
263
|
+
: nil;
|
|
264
|
+
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:options];
|
|
265
|
+
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];
|
|
266
|
+
AVPlayer *player = [AVPlayer playerWithPlayerItem:item];
|
|
267
|
+
|
|
268
|
+
AVPlayerViewController *playerVC = [[AVPlayerViewController alloc] init];
|
|
269
|
+
playerVC.player = player;
|
|
270
|
+
[topVC presentViewController:playerVC animated:YES completion:^{
|
|
271
|
+
[player play];
|
|
272
|
+
resolve(@(YES));
|
|
273
|
+
}];
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
RCT_EXPORT_METHOD(createNotificationChannel:(NSString *)channelId
|
|
278
|
+
channelName:(NSString *)channelName
|
|
279
|
+
description:(NSString *)description
|
|
280
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
281
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
282
|
+
// No-op on iOS (Android notification channels only)
|
|
283
|
+
resolve(@(YES));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
- (void)finishPickWithResult:(nullable id)result error:(nullable NSError *)error {
|
|
287
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
288
|
+
RCTPromiseResolveBlock resolve = self.pendingPickResolve;
|
|
289
|
+
RCTPromiseRejectBlock reject = self.pendingPickReject;
|
|
290
|
+
self.pendingPickResolve = nil;
|
|
291
|
+
self.pendingPickReject = nil;
|
|
292
|
+
|
|
293
|
+
if (error && reject) {
|
|
294
|
+
reject(@"pick_error", error.localizedDescription, error);
|
|
295
|
+
} else if (resolve) {
|
|
296
|
+
resolve(result ?: [NSNull null]);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
- (nullable NSDictionary *)saveImageToTempFile:(UIImage *)image preferredName:(nullable NSString *)preferredName {
|
|
302
|
+
if (!image) return nil;
|
|
303
|
+
NSData *data = UIImageJPEGRepresentation(image, 0.9);
|
|
304
|
+
NSString *ext = @"jpg";
|
|
305
|
+
NSString *mime = @"image/jpeg";
|
|
306
|
+
if (!data) {
|
|
307
|
+
data = UIImagePNGRepresentation(image);
|
|
308
|
+
ext = @"png";
|
|
309
|
+
mime = @"image/png";
|
|
310
|
+
}
|
|
311
|
+
if (!data) return nil;
|
|
312
|
+
|
|
313
|
+
NSString *fileName = preferredName.length > 0
|
|
314
|
+
? [NSString stringWithFormat:@"%@.%@", [preferredName stringByDeletingPathExtension], ext]
|
|
315
|
+
: [NSString stringWithFormat:@"feeddo_%@.%@", [[NSUUID UUID] UUIDString], ext];
|
|
316
|
+
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:
|
|
317
|
+
[NSString stringWithFormat:@"%@_%@", [[NSUUID UUID] UUIDString], fileName]];
|
|
318
|
+
if (![data writeToFile:path atomically:YES]) {
|
|
319
|
+
return nil;
|
|
320
|
+
}
|
|
321
|
+
NSURL *fileURL = [NSURL fileURLWithPath:path];
|
|
322
|
+
return @{
|
|
323
|
+
@"uri": fileURL.absoluteString,
|
|
324
|
+
@"name": fileName,
|
|
325
|
+
@"type": mime
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController {
|
|
330
|
+
[self finishPickWithResult:nil error:nil];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
#if __has_include(<PhotosUI/PhotosUI.h>)
|
|
334
|
+
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results API_AVAILABLE(ios(14)) {
|
|
335
|
+
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
336
|
+
|
|
337
|
+
if (results.count == 0) {
|
|
338
|
+
[self finishPickWithResult:nil error:nil];
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
PHPickerResult *first = results.firstObject;
|
|
343
|
+
NSItemProvider *provider = first.itemProvider;
|
|
344
|
+
|
|
345
|
+
if (@available(iOS 14.0, *)) {
|
|
346
|
+
if ([provider hasItemConformingToTypeIdentifier:UTTypeImage.identifier]) {
|
|
347
|
+
NSString *suggested = provider.suggestedName;
|
|
348
|
+
[provider loadFileRepresentationForTypeIdentifier:UTTypeImage.identifier completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
|
|
349
|
+
if (url) {
|
|
350
|
+
NSString *ext = url.pathExtension.lowercaseString;
|
|
351
|
+
if (ext.length == 0) ext = @"jpg";
|
|
352
|
+
NSString *mime = @"image/jpeg";
|
|
353
|
+
if ([ext isEqualToString:@"png"]) mime = @"image/png";
|
|
354
|
+
else if ([ext isEqualToString:@"gif"]) mime = @"image/gif";
|
|
355
|
+
else if ([ext isEqualToString:@"webp"]) mime = @"image/webp";
|
|
356
|
+
else if ([ext isEqualToString:@"heic"] || [ext isEqualToString:@"heif"]) {
|
|
357
|
+
// Convert HEIC to JPEG for broad server/preview compatibility
|
|
358
|
+
NSData *rawData = [NSData dataWithContentsOfURL:url];
|
|
359
|
+
UIImage *img = rawData ? [UIImage imageWithData:rawData] : nil;
|
|
360
|
+
NSDictionary *converted = [self saveImageToTempFile:img preferredName:suggested];
|
|
361
|
+
if (converted) {
|
|
362
|
+
[self finishPickWithResult:converted error:nil];
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
NSString *fileName = suggested.length > 0
|
|
368
|
+
? [NSString stringWithFormat:@"%@.%@", [suggested stringByDeletingPathExtension], ext]
|
|
369
|
+
: (url.lastPathComponent ?: [NSString stringWithFormat:@"image.%@", ext]);
|
|
370
|
+
NSString *destPath = [NSTemporaryDirectory() stringByAppendingPathComponent:
|
|
371
|
+
[NSString stringWithFormat:@"%@_%@", [[NSUUID UUID] UUIDString], fileName]];
|
|
372
|
+
NSURL *destURL = [NSURL fileURLWithPath:destPath];
|
|
373
|
+
NSError *copyErr = nil;
|
|
374
|
+
if ([[NSFileManager defaultManager] copyItemAtURL:url toURL:destURL error:©Err]) {
|
|
375
|
+
[self finishPickWithResult:@{
|
|
376
|
+
@"uri": destURL.absoluteString,
|
|
377
|
+
@"name": fileName,
|
|
378
|
+
@"type": mime
|
|
379
|
+
} error:nil];
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if ([provider canLoadObjectOfClass:[UIImage class]]) {
|
|
385
|
+
[provider loadObjectOfClass:[UIImage class] completionHandler:^(id<NSItemProviderReading> _Nullable object, NSError * _Nullable loadErr) {
|
|
386
|
+
UIImage *img = [object isKindOfClass:[UIImage class]] ? (UIImage *)object : nil;
|
|
387
|
+
NSDictionary *res = [self saveImageToTempFile:img preferredName:suggested];
|
|
388
|
+
[self finishPickWithResult:res error:res ? nil : loadErr];
|
|
389
|
+
}];
|
|
390
|
+
} else {
|
|
391
|
+
[self finishPickWithResult:nil error:error];
|
|
392
|
+
}
|
|
393
|
+
}];
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
[self finishPickWithResult:nil error:nil];
|
|
399
|
+
}
|
|
400
|
+
#endif
|
|
401
|
+
|
|
402
|
+
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
|
403
|
+
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
404
|
+
[self finishPickWithResult:nil error:nil];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
|
|
408
|
+
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
409
|
+
NSURL *imageURL = info[UIImagePickerControllerImageURL];
|
|
410
|
+
if (imageURL) {
|
|
411
|
+
NSString *ext = imageURL.pathExtension.lowercaseString ?: @"jpg";
|
|
412
|
+
NSString *mime = [ext isEqualToString:@"png"] ? @"image/png" : @"image/jpeg";
|
|
413
|
+
NSString *fileName = imageURL.lastPathComponent ?: [NSString stringWithFormat:@"image.%@", ext];
|
|
414
|
+
NSString *destPath = [NSTemporaryDirectory() stringByAppendingPathComponent:
|
|
415
|
+
[NSString stringWithFormat:@"%@_%@", [[NSUUID UUID] UUIDString], fileName]];
|
|
416
|
+
NSURL *destURL = [NSURL fileURLWithPath:destPath];
|
|
417
|
+
if ([[NSFileManager defaultManager] copyItemAtURL:imageURL toURL:destURL error:nil]) {
|
|
418
|
+
[self finishPickWithResult:@{
|
|
419
|
+
@"uri": destURL.absoluteString,
|
|
420
|
+
@"name": fileName,
|
|
421
|
+
@"type": mime
|
|
422
|
+
} error:nil];
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
UIImage *img = info[UIImagePickerControllerOriginalImage];
|
|
427
|
+
NSDictionary *res = [self saveImageToTempFile:img preferredName:nil];
|
|
428
|
+
[self finishPickWithResult:res error:nil];
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
@end
|
|
432
|
+
|
|
433
|
+
// ============================================================================
|
|
434
|
+
// FeeddoReactNativeApnsModule: Direct APNs Bridge (opt-in, zero AppDelegate code)
|
|
435
|
+
// ============================================================================
|
|
436
|
+
static NSString *sCachedApnsToken = nil;
|
|
437
|
+
static NSDictionary *sPendingInitialNotification = nil;
|
|
438
|
+
static __weak FeeddoReactNativeApnsModule *sActiveApnsModule = nil;
|
|
439
|
+
static BOOL sApnsInitialized = NO;
|
|
440
|
+
static BOOL sApnsHooksInstalled = NO;
|
|
441
|
+
|
|
442
|
+
@interface FeeddoReactNativeApnsModule () <UNUserNotificationCenterDelegate>
|
|
443
|
+
@property (nonatomic, weak, nullable) id<UNUserNotificationCenterDelegate> previousCenterDelegate;
|
|
444
|
+
@property (nonatomic, assign) BOOL hasListeners;
|
|
445
|
+
@property (nonatomic, assign) BOOL foregroundAlert;
|
|
446
|
+
@property (nonatomic, assign) BOOL foregroundBadge;
|
|
447
|
+
@property (nonatomic, assign) BOOL foregroundSound;
|
|
448
|
+
- (void)emitTokenEvent:(NSString *)token;
|
|
449
|
+
- (void)emitErrorEvent:(NSString *)message;
|
|
450
|
+
@end
|
|
451
|
+
|
|
452
|
+
static void (*sOrigDidRegisterIMP)(id, SEL, UIApplication *, NSData *) = NULL;
|
|
453
|
+
static void (*sOrigDidFailIMP)(id, SEL, UIApplication *, NSError *) = NULL;
|
|
454
|
+
|
|
455
|
+
__attribute__((constructor))
|
|
456
|
+
static void FeeddoRegisterRemoteLaunchObserver(void) {
|
|
457
|
+
@autoreleasepool {
|
|
458
|
+
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidFinishLaunchingNotification
|
|
459
|
+
object:nil
|
|
460
|
+
queue:nil
|
|
461
|
+
usingBlock:^(NSNotification *note) {
|
|
462
|
+
NSDictionary *remoteNotif = note.userInfo[UIApplicationLaunchOptionsRemoteNotificationKey];
|
|
463
|
+
if ([remoteNotif isKindOfClass:[NSDictionary class]]) {
|
|
464
|
+
sPendingInitialNotification = FeeddoNormalizeNotificationPayload(remoteNotif);
|
|
465
|
+
}
|
|
466
|
+
}];
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
static void FeeddoSwizzledDidRegister(id self, SEL _cmd, UIApplication *application, NSData *deviceToken) {
|
|
471
|
+
const unsigned char *bytes = (const unsigned char *)deviceToken.bytes;
|
|
472
|
+
NSMutableString *hexToken = [NSMutableString stringWithCapacity:deviceToken.length * 2];
|
|
473
|
+
for (NSUInteger i = 0; i < deviceToken.length; i++) {
|
|
474
|
+
[hexToken appendFormat:@"%02.2hhx", bytes[i]];
|
|
475
|
+
}
|
|
476
|
+
NSString *tokenCopy = [hexToken copy];
|
|
477
|
+
sCachedApnsToken = tokenCopy;
|
|
478
|
+
|
|
479
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
480
|
+
FeeddoReactNativeApnsModule *module = sActiveApnsModule;
|
|
481
|
+
if (module) {
|
|
482
|
+
[module emitTokenEvent:tokenCopy];
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
if (sOrigDidRegisterIMP) {
|
|
487
|
+
sOrigDidRegisterIMP(self, _cmd, application, deviceToken);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
static void FeeddoSwizzledDidFail(id self, SEL _cmd, UIApplication *application, NSError *error) {
|
|
492
|
+
NSString *errorDesc = error.localizedDescription;
|
|
493
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
494
|
+
FeeddoReactNativeApnsModule *module = sActiveApnsModule;
|
|
495
|
+
if (module && errorDesc.length > 0) {
|
|
496
|
+
[module emitErrorEvent:errorDesc];
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
if (sOrigDidFailIMP) {
|
|
501
|
+
sOrigDidFailIMP(self, _cmd, application, error);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
@implementation FeeddoReactNativeApnsModule
|
|
506
|
+
|
|
507
|
+
RCT_EXPORT_MODULE(FeeddoReactNativeApns);
|
|
508
|
+
|
|
509
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
510
|
+
return YES;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
- (instancetype)init {
|
|
514
|
+
if (self = [super init]) {
|
|
515
|
+
_foregroundAlert = NO;
|
|
516
|
+
_foregroundBadge = YES;
|
|
517
|
+
_foregroundSound = NO;
|
|
518
|
+
sActiveApnsModule = self;
|
|
519
|
+
}
|
|
520
|
+
return self;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
524
|
+
return @[
|
|
525
|
+
@"FeeddoApnsToken",
|
|
526
|
+
@"FeeddoApnsError",
|
|
527
|
+
@"FeeddoApnsNotificationOpened",
|
|
528
|
+
@"FeeddoApnsForegroundNotification"
|
|
529
|
+
];
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
- (void)startObserving {
|
|
533
|
+
self.hasListeners = YES;
|
|
534
|
+
sActiveApnsModule = self;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
- (void)stopObserving {
|
|
538
|
+
self.hasListeners = NO;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
- (void)emitTokenEvent:(NSString *)token {
|
|
542
|
+
if (self.hasListeners && token.length > 0) {
|
|
543
|
+
[self sendEventWithName:@"FeeddoApnsToken" body:token];
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
- (void)emitErrorEvent:(NSString *)message {
|
|
548
|
+
if (self.hasListeners && message.length > 0) {
|
|
549
|
+
[self sendEventWithName:@"FeeddoApnsError" body:message];
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
- (void)installAppDelegateHooksIfNeeded {
|
|
554
|
+
if (sApnsHooksInstalled) return;
|
|
555
|
+
id<UIApplicationDelegate> delegate = UIApplication.sharedApplication.delegate;
|
|
556
|
+
if (!delegate) return;
|
|
557
|
+
Class delegateClass = [delegate class];
|
|
558
|
+
|
|
559
|
+
SEL regSel = @selector(application:didRegisterForRemoteNotificationsWithDeviceToken:);
|
|
560
|
+
Method regMethod = class_getInstanceMethod(delegateClass, regSel);
|
|
561
|
+
if (regMethod) {
|
|
562
|
+
IMP orig = method_getImplementation(regMethod);
|
|
563
|
+
if (orig != (IMP)FeeddoSwizzledDidRegister) {
|
|
564
|
+
sOrigDidRegisterIMP = (void (*)(id, SEL, UIApplication *, NSData *))orig;
|
|
565
|
+
method_setImplementation(regMethod, (IMP)FeeddoSwizzledDidRegister);
|
|
566
|
+
}
|
|
567
|
+
} else {
|
|
568
|
+
class_addMethod(delegateClass, regSel, (IMP)FeeddoSwizzledDidRegister, "v@:@@");
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
SEL failSel = @selector(application:didFailToRegisterForRemoteNotificationsWithError:);
|
|
572
|
+
Method failMethod = class_getInstanceMethod(delegateClass, failSel);
|
|
573
|
+
if (failMethod) {
|
|
574
|
+
IMP orig = method_getImplementation(failMethod);
|
|
575
|
+
if (orig != (IMP)FeeddoSwizzledDidFail) {
|
|
576
|
+
sOrigDidFailIMP = (void (*)(id, SEL, UIApplication *, NSError *))orig;
|
|
577
|
+
method_setImplementation(failMethod, (IMP)FeeddoSwizzledDidFail);
|
|
578
|
+
}
|
|
579
|
+
} else {
|
|
580
|
+
class_addMethod(delegateClass, failSel, (IMP)FeeddoSwizzledDidFail, "v@:@@");
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
sApnsHooksInstalled = YES;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
- (void)setupNotificationCenterDelegate {
|
|
587
|
+
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
588
|
+
if (center.delegate && center.delegate != self) {
|
|
589
|
+
self.previousCenterDelegate = center.delegate;
|
|
590
|
+
}
|
|
591
|
+
center.delegate = self;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// MARK: - UNUserNotificationCenterDelegate
|
|
595
|
+
|
|
596
|
+
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
597
|
+
willPresentNotification:(UNNotification *)notification
|
|
598
|
+
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
|
|
599
|
+
BOOL isPush = [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]];
|
|
600
|
+
if (isPush) {
|
|
601
|
+
NSDictionary *payload = FeeddoNormalizeNotificationPayload(notification.request.content.userInfo);
|
|
602
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
603
|
+
if (self.hasListeners) {
|
|
604
|
+
[self sendEventWithName:@"FeeddoApnsForegroundNotification" body:payload];
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
UNNotificationPresentationOptions options = UNNotificationPresentationOptionNone;
|
|
609
|
+
if (self.foregroundBadge) {
|
|
610
|
+
options |= UNNotificationPresentationOptionBadge;
|
|
611
|
+
}
|
|
612
|
+
if (self.foregroundSound) {
|
|
613
|
+
options |= UNNotificationPresentationOptionSound;
|
|
614
|
+
}
|
|
615
|
+
if (self.foregroundAlert) {
|
|
616
|
+
if (@available(iOS 14.0, *)) {
|
|
617
|
+
options |= (UNNotificationPresentationOptionBanner | UNNotificationPresentationOptionList);
|
|
618
|
+
} else {
|
|
619
|
+
#pragma clang diagnostic push
|
|
620
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
621
|
+
options |= UNNotificationPresentationOptionAlert;
|
|
622
|
+
#pragma clang diagnostic pop
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
completionHandler(options);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
id<UNUserNotificationCenterDelegate> prev = self.previousCenterDelegate;
|
|
630
|
+
if (prev && [prev respondsToSelector:@selector(userNotificationCenter:willPresentNotification:withCompletionHandler:)]) {
|
|
631
|
+
[prev userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
|
|
632
|
+
} else {
|
|
633
|
+
UNNotificationPresentationOptions options = UNNotificationPresentationOptionNone;
|
|
634
|
+
if (self.foregroundBadge) options |= UNNotificationPresentationOptionBadge;
|
|
635
|
+
if (self.foregroundSound) options |= UNNotificationPresentationOptionSound;
|
|
636
|
+
if (self.foregroundAlert) {
|
|
637
|
+
if (@available(iOS 14.0, *)) {
|
|
638
|
+
options |= (UNNotificationPresentationOptionBanner | UNNotificationPresentationOptionList);
|
|
639
|
+
} else {
|
|
640
|
+
#pragma clang diagnostic push
|
|
641
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
642
|
+
options |= UNNotificationPresentationOptionAlert;
|
|
643
|
+
#pragma clang diagnostic pop
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
completionHandler(options);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
651
|
+
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|
652
|
+
withCompletionHandler:(void (^)(void))completionHandler {
|
|
653
|
+
BOOL isPush = [response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]];
|
|
654
|
+
if (isPush) {
|
|
655
|
+
NSDictionary *payload = FeeddoNormalizeNotificationPayload(response.notification.request.content.userInfo);
|
|
656
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
657
|
+
if (self.hasListeners && sApnsInitialized) {
|
|
658
|
+
[self sendEventWithName:@"FeeddoApnsNotificationOpened" body:payload];
|
|
659
|
+
} else {
|
|
660
|
+
sPendingInitialNotification = payload;
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
completionHandler();
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
id<UNUserNotificationCenterDelegate> prev = self.previousCenterDelegate;
|
|
668
|
+
if (prev && [prev respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) {
|
|
669
|
+
[prev userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
|
|
670
|
+
} else {
|
|
671
|
+
completionHandler();
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// MARK: - React Native Methods
|
|
676
|
+
|
|
677
|
+
RCT_EXPORT_METHOD(initialize:(BOOL)autoRegister
|
|
678
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
679
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
680
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
681
|
+
sActiveApnsModule = self;
|
|
682
|
+
sApnsInitialized = YES;
|
|
683
|
+
[self installAppDelegateHooksIfNeeded];
|
|
684
|
+
[self setupNotificationCenterDelegate];
|
|
685
|
+
|
|
686
|
+
if (autoRegister) {
|
|
687
|
+
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
NSDictionary *initial = sPendingInitialNotification;
|
|
691
|
+
sPendingInitialNotification = nil;
|
|
692
|
+
|
|
693
|
+
NSMutableDictionary *response = [NSMutableDictionary dictionary];
|
|
694
|
+
if (sCachedApnsToken) {
|
|
695
|
+
response[@"token"] = sCachedApnsToken;
|
|
696
|
+
}
|
|
697
|
+
if (initial) {
|
|
698
|
+
response[@"initialNotification"] = initial;
|
|
699
|
+
}
|
|
700
|
+
resolve(response);
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
RCT_EXPORT_METHOD(requestNotificationPermissions:(NSDictionary *)args
|
|
705
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
706
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
707
|
+
UNAuthorizationOptions options = 0;
|
|
708
|
+
BOOL alert = args[@"alert"] ? [args[@"alert"] boolValue] : YES;
|
|
709
|
+
BOOL badge = args[@"badge"] ? [args[@"badge"] boolValue] : YES;
|
|
710
|
+
BOOL sound = args[@"sound"] ? [args[@"sound"] boolValue] : YES;
|
|
711
|
+
BOOL provisional = args[@"provisional"] ? [args[@"provisional"] boolValue] : NO;
|
|
712
|
+
BOOL criticalAlert = args[@"criticalAlert"] ? [args[@"criticalAlert"] boolValue] : NO;
|
|
713
|
+
|
|
714
|
+
if (alert) options |= UNAuthorizationOptionAlert;
|
|
715
|
+
if (badge) options |= UNAuthorizationOptionBadge;
|
|
716
|
+
if (sound) options |= UNAuthorizationOptionSound;
|
|
717
|
+
if (provisional) {
|
|
718
|
+
if (@available(iOS 12.0, *)) {
|
|
719
|
+
options |= UNAuthorizationOptionProvisional;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
if (criticalAlert) {
|
|
723
|
+
if (@available(iOS 12.0, *)) {
|
|
724
|
+
options |= UNAuthorizationOptionCriticalAlert;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
if (options == 0) {
|
|
728
|
+
options = (UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:options
|
|
732
|
+
completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
|
733
|
+
if (granted) {
|
|
734
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
735
|
+
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
739
|
+
resolve(@{
|
|
740
|
+
@"granted": @(granted),
|
|
741
|
+
@"error": error ? error.localizedDescription : [NSNull null]
|
|
742
|
+
});
|
|
743
|
+
});
|
|
744
|
+
}];
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
RCT_EXPORT_METHOD(getNotificationSettings:(RCTPromiseResolveBlock)resolve
|
|
748
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
749
|
+
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
|
|
750
|
+
NSString *statusStr = @"notDetermined";
|
|
751
|
+
switch (settings.authorizationStatus) {
|
|
752
|
+
case UNAuthorizationStatusAuthorized:
|
|
753
|
+
statusStr = @"authorized";
|
|
754
|
+
break;
|
|
755
|
+
case UNAuthorizationStatusDenied:
|
|
756
|
+
statusStr = @"denied";
|
|
757
|
+
break;
|
|
758
|
+
case UNAuthorizationStatusNotDetermined:
|
|
759
|
+
statusStr = @"notDetermined";
|
|
760
|
+
break;
|
|
761
|
+
case UNAuthorizationStatusProvisional:
|
|
762
|
+
statusStr = @"provisional";
|
|
763
|
+
break;
|
|
764
|
+
default:
|
|
765
|
+
if (@available(iOS 14.0, *)) {
|
|
766
|
+
if (settings.authorizationStatus == UNAuthorizationStatusEphemeral) {
|
|
767
|
+
statusStr = @"ephemeral";
|
|
768
|
+
} else {
|
|
769
|
+
statusStr = @"unknown";
|
|
770
|
+
}
|
|
771
|
+
} else {
|
|
772
|
+
statusStr = @"unknown";
|
|
773
|
+
}
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
778
|
+
resolve(@{
|
|
779
|
+
@"authorizationStatus": statusStr,
|
|
780
|
+
@"soundEnabled": @(settings.soundSetting == UNNotificationSettingEnabled),
|
|
781
|
+
@"badgeEnabled": @(settings.badgeSetting == UNNotificationSettingEnabled),
|
|
782
|
+
@"alertEnabled": @(settings.alertSetting == UNNotificationSettingEnabled)
|
|
783
|
+
});
|
|
784
|
+
});
|
|
785
|
+
}];
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
RCT_EXPORT_METHOD(getDeviceToken:(RCTPromiseResolveBlock)resolve
|
|
789
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
790
|
+
resolve(sCachedApnsToken ?: [NSNull null]);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve
|
|
794
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
795
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
796
|
+
NSDictionary *initial = sPendingInitialNotification;
|
|
797
|
+
sPendingInitialNotification = nil;
|
|
798
|
+
resolve(initial ?: [NSNull null]);
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
RCT_EXPORT_METHOD(registerForRemoteNotifications:(RCTPromiseResolveBlock)resolve
|
|
803
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
804
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
805
|
+
[self installAppDelegateHooksIfNeeded];
|
|
806
|
+
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
|
807
|
+
resolve(sCachedApnsToken ?: [NSNull null]);
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
RCT_EXPORT_METHOD(unregisterForRemoteNotifications:(RCTPromiseResolveBlock)resolve
|
|
812
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
813
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
814
|
+
sCachedApnsToken = nil;
|
|
815
|
+
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
|
|
816
|
+
resolve(@(YES));
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
RCT_EXPORT_METHOD(setForegroundNotificationPresentationOptions:(NSDictionary *)args
|
|
821
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
822
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
823
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
824
|
+
self.foregroundAlert = args[@"alert"] ? [args[@"alert"] boolValue] : NO;
|
|
825
|
+
self.foregroundBadge = args[@"badge"] ? [args[@"badge"] boolValue] : YES;
|
|
826
|
+
self.foregroundSound = args[@"sound"] ? [args[@"sound"] boolValue] : NO;
|
|
827
|
+
resolve(@(YES));
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
@end
|