- App.tsx: full navigation (Auth stack + Main tabs with 5 screens) - Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen - HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors - MapScreen: interactive map with layer toggles (6 layers) - MarketplaceScreen: categories (6), products (5), search - ChatScreen: AI chat with quick prompts (4), bot responses - ProfileScreen: user info, stats, menu (9 items), logout - AlertsScreen: alert list with severity, acknowledge - SensorsScreen: sensor list with type filters (6 types), search - ZonesScreen: zone cards with stats - SettingsScreen: language picker (FR/EN/ES/DE), privacy, about - Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n - Hooks: useSensors, useAlerts, useNotifications, useLocation - Components: Card, Button, LoadingSpinner, ErrorBoundary, Header - Services: iotService, notificationService (with axios API client) - Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN) - Theme: colors.ts with full design system (Blue Ocean palette) - Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
112 lines
5.2 KiB
Objective-C
112 lines
5.2 KiB
Objective-C
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
|
|
#import <ExpoModulesCore/EXDefines.h>
|
|
#import <EXNotifications/EXNotificationBuilder.h>
|
|
#import <EXNotifications/NSDictionary+EXNotificationsVerifyingClass.h>
|
|
|
|
@implementation EXNotificationBuilder
|
|
|
|
EX_REGISTER_MODULE();
|
|
|
|
+ (const NSArray<Protocol *> *)exportedInterfaces
|
|
{
|
|
return @[@protocol(EXNotificationBuilder)];
|
|
}
|
|
|
|
- (UNMutableNotificationContent *)notificationContentFromRequest:(NSDictionary *)request
|
|
{
|
|
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
|
|
[content setTitle:[request objectForKey:@"title" verifyingClass:[NSString class]]];
|
|
[content setSubtitle:[request objectForKey:@"subtitle" verifyingClass:[NSString class]]];
|
|
[content setBody:[request objectForKey:@"body" verifyingClass:[NSString class]]];
|
|
[content setLaunchImageName:[request objectForKey:@"launchImageName" verifyingClass:[NSString class]]];
|
|
[content setBadge:[request objectForKey:@"badge" verifyingClass:[NSNumber class]]];
|
|
[content setUserInfo:[request objectForKey:@"data" verifyingClass:[NSDictionary class]]];
|
|
[content setCategoryIdentifier:[request objectForKey:@"categoryIdentifier" verifyingClass:[NSString class]]];
|
|
if ([request[@"sound"] isKindOfClass:[NSNumber class]]) {
|
|
[content setSound:[request[@"sound"] boolValue] ? [UNNotificationSound defaultSound] : nil];
|
|
} else if ([request[@"sound"] isKindOfClass:[NSString class]]) {
|
|
NSString *soundName = request[@"sound"];
|
|
if ([@"default" isEqualToString:soundName]) {
|
|
[content setSound:[UNNotificationSound defaultSound]];
|
|
} else if ([@"defaultCritical" isEqualToString:soundName]) {
|
|
if (@available(iOS 12.0, *)) {
|
|
[content setSound:[UNNotificationSound defaultCriticalSound]];
|
|
} else {
|
|
[content setSound:[UNNotificationSound defaultSound]];
|
|
}
|
|
} else {
|
|
[content setSound:[UNNotificationSound soundNamed:soundName]];
|
|
}
|
|
}
|
|
NSMutableArray<UNNotificationAttachment *> *attachments = [NSMutableArray new];
|
|
[[request objectForKey:@"attachments" verifyingClass:[NSArray class]] enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
UNNotificationAttachment *attachment = [self attachmentFromRequest:obj];
|
|
if (attachment) {
|
|
[attachments addObject:attachment];
|
|
}
|
|
}];
|
|
[content setAttachments:attachments];
|
|
if (@available(iOS 15.0, *)) {
|
|
NSString *interruptionLevel = [request objectForKey:@"interruptionLevel" verifyingClass:[NSString class]];
|
|
if (interruptionLevel) {
|
|
content.interruptionLevel = [EXNotificationBuilder deserializeInterruptionLevel:interruptionLevel];
|
|
}
|
|
}
|
|
return content;
|
|
}
|
|
|
|
+ (UNNotificationInterruptionLevel)deserializeInterruptionLevel:(NSString *)interruptionLevel API_AVAILABLE(ios(15.0)) {
|
|
static NSDictionary *interruptionLevelMap;
|
|
if (!interruptionLevelMap) {
|
|
interruptionLevelMap = @{
|
|
@"passive": @(UNNotificationInterruptionLevelPassive),
|
|
@"active": @(UNNotificationInterruptionLevelActive),
|
|
@"timeSensitive": @(UNNotificationInterruptionLevelTimeSensitive),
|
|
@"critical": @(UNNotificationInterruptionLevelCritical)
|
|
};
|
|
}
|
|
|
|
return [interruptionLevelMap[interruptionLevel] integerValue];
|
|
}
|
|
|
|
- (UNNotificationAttachment *)attachmentFromRequest:(NSDictionary *)request
|
|
{
|
|
NSString *identifier = [request objectForKey:@"identifier" verifyingClass:[NSString class]] ?: @"";
|
|
NSURL *uri = [NSURL URLWithString:[request objectForKey:@"uri" verifyingClass:[NSString class]]];
|
|
NSError *error = nil;
|
|
UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:identifier URL:uri options:[self attachmentOptionsFromRequest:request] error:&error];
|
|
if (error) {
|
|
EXLogWarn(@"[expo-notifications] Could not have created a notification attachment out of request: %@. Error: %@.", [request description], [error description]);
|
|
return nil;
|
|
}
|
|
return attachment;
|
|
}
|
|
|
|
- (NSDictionary *)attachmentOptionsFromRequest:(NSDictionary *)request
|
|
{
|
|
NSMutableDictionary *options = [NSMutableDictionary new];
|
|
if ([request objectForKey:@"typeHint" verifyingClass:[NSString class]]) {
|
|
options[UNNotificationAttachmentOptionsTypeHintKey] = request[@"typeHint"];
|
|
}
|
|
if ([request objectForKey:@"hideThumbnail" verifyingClass:[NSNumber class]]) {
|
|
options[UNNotificationAttachmentOptionsThumbnailHiddenKey] = request[@"hideThumbnail"];
|
|
}
|
|
if ([request objectForKey:@"thumbnailClipArea" verifyingClass:[NSDictionary class]]) {
|
|
NSDictionary *area = request[@"thumbnailClipArea"];
|
|
NSNumber *x = [area objectForKey:@"x" verifyingClass:[NSNumber class]];
|
|
NSNumber *y = [area objectForKey:@"y" verifyingClass:[NSNumber class]];
|
|
NSNumber *width = [area objectForKey:@"width" verifyingClass:[NSNumber class]];
|
|
NSNumber *height = [area objectForKey:@"height" verifyingClass:[NSNumber class]];
|
|
CGRect areaRect = CGRectMake([x doubleValue], [y doubleValue], [width doubleValue], [height doubleValue]);
|
|
options[UNNotificationAttachmentOptionsThumbnailClippingRectKey] = (__bridge id _Nullable)(CGRectCreateDictionaryRepresentation(areaRect));
|
|
}
|
|
if ([request objectForKey:@"thumbnailTime" verifyingClass:[NSNumber class]]) {
|
|
options[UNNotificationAttachmentOptionsThumbnailTimeKey] = request[@"thumbnailTime"];
|
|
}
|
|
return options;
|
|
}
|
|
|
|
@end
|
|
|