- 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
136 lines
4.8 KiB
Objective-C
136 lines
4.8 KiB
Objective-C
// Copyright 2016-present 650 Industries. All rights reserved.
|
|
|
|
#import <EXNotifications/EXLegacyRemoteNotificationPermissionRequester.h>
|
|
#import <ExpoModulesCore/EXUtilities.h>
|
|
|
|
@interface EXLegacyRemoteNotificationPermissionRequester ()
|
|
|
|
@property (nonatomic, strong) EXPromiseResolveBlock resolve;
|
|
@property (nonatomic, strong) EXPromiseRejectBlock reject;
|
|
@property (nonatomic, assign) BOOL remoteNotificationsRegistrationIsPending;
|
|
@property (nonatomic, weak) id<EXPermissionsRequester> userNotificationPermissionRequester;
|
|
@property (nonatomic, weak) dispatch_queue_t methodQueue;
|
|
@property (nonatomic, weak) id<EXRemoteNotificationPermissionProgressPublisher> permissionProgressPublisher;
|
|
|
|
@end
|
|
|
|
@implementation EXLegacyRemoteNotificationPermissionRequester
|
|
|
|
+ (NSString *)permissionType
|
|
{
|
|
return @"notifications";
|
|
}
|
|
|
|
- (instancetype)initWithUserNotificationPermissionRequester:(id<EXPermissionsRequester>)userNotificationPermissionRequester
|
|
permissionPublisher:(id<EXRemoteNotificationPermissionProgressPublisher>)permissionProgressPublisher
|
|
withMethodQueue:(dispatch_queue_t)methodQueue
|
|
{
|
|
if (self = [super init]) {
|
|
_remoteNotificationsRegistrationIsPending = NO;
|
|
_permissionProgressPublisher = permissionProgressPublisher;
|
|
_userNotificationPermissionRequester = userNotificationPermissionRequester;
|
|
_methodQueue = methodQueue;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSDictionary *)getPermissions
|
|
{
|
|
__block EXPermissionStatus status;
|
|
[EXUtilities performSynchronouslyOnMainThread:^{
|
|
status = (UMSharedApplication().isRegisteredForRemoteNotifications) ?
|
|
EXPermissionStatusGranted :
|
|
EXPermissionStatusUndetermined;
|
|
}];
|
|
NSMutableDictionary *permissions = [[_userNotificationPermissionRequester getPermissions] mutableCopy];
|
|
|
|
[permissions setValuesForKeysWithDictionary:@{
|
|
@"status": @(status),
|
|
|
|
}];
|
|
return permissions;
|
|
}
|
|
|
|
- (void)requestPermissionsWithResolver:(EXPromiseResolveBlock)resolve rejecter:(EXPromiseRejectBlock)reject
|
|
{
|
|
if (_resolve != nil || _reject != nil) {
|
|
reject(@"E_AWAIT_PROMISE", @"Another request for the same permission is already being handled.", nil);
|
|
return;
|
|
}
|
|
|
|
_resolve = resolve;
|
|
_reject = reject;
|
|
|
|
BOOL __block isRegisteredForRemoteNotifications = NO;
|
|
[EXUtilities performSynchronouslyOnMainThread:^{
|
|
isRegisteredForRemoteNotifications = UMSharedApplication().isRegisteredForRemoteNotifications;
|
|
}];
|
|
|
|
if (isRegisteredForRemoteNotifications) {
|
|
// resolve immediately if already registered
|
|
[self _maybeConsumeResolverWithCurrentPermissions];
|
|
} else {
|
|
[_permissionProgressPublisher addDelegate:self];
|
|
EX_WEAKIFY(self)
|
|
[_userNotificationPermissionRequester requestPermissionsWithResolver:^(NSDictionary *permission){
|
|
EX_STRONGIFY(self)
|
|
EXPermissionStatus localNotificationsStatus = [[permission objectForKey:@"status"] intValue];
|
|
// We may assume that `EXLocalNotificationRequester`'s permission request will always finish
|
|
// when the user responds to the dialog or has already responded in the past.
|
|
// However, `UIApplication.registerForRemoteNotification` results in calling
|
|
// `application:didRegisterForRemoteNotificationsWithDeviceToken:` or
|
|
// `application:didFailToRegisterForRemoteNotificationsWithError:` on the application delegate
|
|
// ONLY when the notifications are enabled in settings (by allowing sound, alerts or app badge).
|
|
// So, when the local notifications are disabled, the application delegate's callbacks will not be called instantly.
|
|
if (localNotificationsStatus == EXPermissionStatusDenied) {
|
|
[self _clearObserver];
|
|
[self _maybeConsumeResolverWithCurrentPermissions];
|
|
} else {
|
|
self.remoteNotificationsRegistrationIsPending = YES;
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[UMSharedApplication() registerForRemoteNotifications];
|
|
});
|
|
}
|
|
} rejecter:^(NSString *code, NSString *message, NSError *error){
|
|
[self _clearObserver];
|
|
if (self.reject) {
|
|
self.reject(code, message, error);
|
|
}
|
|
}];
|
|
}
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
[self _clearObserver];
|
|
}
|
|
|
|
- (void)handleDidFinishRegisteringForRemoteNotifications
|
|
{
|
|
[self _clearObserver];
|
|
EX_WEAKIFY(self)
|
|
dispatch_async(_methodQueue, ^{
|
|
EX_STRONGIFY(self)
|
|
[self _maybeConsumeResolverWithCurrentPermissions];
|
|
});
|
|
}
|
|
|
|
- (void)_clearObserver
|
|
{
|
|
[_permissionProgressPublisher removeDelegate:self];
|
|
_remoteNotificationsRegistrationIsPending = NO;
|
|
}
|
|
|
|
- (void)_maybeConsumeResolverWithCurrentPermissions
|
|
{
|
|
if (!_remoteNotificationsRegistrationIsPending) {
|
|
if (_resolve) {
|
|
_resolve([self getPermissions]);
|
|
_resolve = nil;
|
|
_reject = nil;
|
|
}
|
|
}
|
|
}
|
|
|
|
@end
|