Skip to content

Commit

Permalink
SHK-5083: Add chat notifications on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
mstanic-shake committed Dec 24, 2021
1 parent 1269d00 commit 14041b2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ PODS:
- React
- react-native-shake (14.1.0):
- React
- Shake-Staging (= 15.1.0-rc.1424)
- Shake-Staging (~> 15.1.0-rc.1447)
- react-native-slider (2.0.9):
- React
- react-native-webview (9.3.0):
Expand Down Expand Up @@ -362,7 +362,7 @@ PODS:
- React
- RNScreens (2.7.0):
- React
- Shake-Staging (15.1.0-rc.1424)
- Shake-Staging (15.1.0-rc.1447)
- Yoga (1.14.0)
- YogaKit (1.18.1):
- Yoga (~> 1.14)
Expand Down Expand Up @@ -573,7 +573,7 @@ SPEC CHECKSUMS:
react-native-checkbox: 2d04aeb0c7e2c2cbd9a9a902ca6a5cf642688d09
react-native-maps: f4b89da81626ad7f151a8bfcb79733295d31ce5c
react-native-safe-area-context: 8260e5157617df4b72865f44006797f895b2ada7
react-native-shake: 5c7e715a7370728f3c31bcca53b313cf6ff6e7e0
react-native-shake: 9b00818158045abdb40f16e8ce3c039e39c9f8b4
react-native-slider: b34d943dc60deb96d952ba6b6b249aa8091e86da
react-native-webview: bdde2a3c4cbdc0122bc2bfba13603db193f0cc5c
React-perflogger: fd28ee1f2b5b150b00043f0301d96bd417fdc339
Expand All @@ -596,10 +596,10 @@ SPEC CHECKSUMS:
RNGestureHandler: a479ebd5ed4221a810967000735517df0d2db211
RNReanimated: 955cf4068714003d2f1a6e2bae3fb1118f359aff
RNScreens: cf198f915f8a2bf163de94ca9f5bfc8d326c3706
Shake-Staging: 077f520696ad54f58e83144849cc0d0655c386fa
Shake-Staging: 1e48bab5826b8192d7c0a3917f3e1e7d44d6b02e
Yoga: aa0cb45287ebe1004c02a13f279c55a95f1572f4
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 63d928e4cc656254d87ffe5a79dedfde1a4b605c
PODFILE CHECKSUM: 3d68bab78d41ff5c76df688461c486e9826619d6

COCOAPODS: 1.11.2
4 changes: 3 additions & 1 deletion example/ios/example/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
@import UserNotifications;

@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate, RCTBridgeDelegate>

@property (nonatomic, strong) UIWindow *window;

Expand Down
29 changes: 29 additions & 0 deletions example/ios/example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>

@import Shake;
@import UserNotifications;

static void InitializeFlipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
Expand All @@ -31,6 +34,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
InitializeFlipper(application);
#endif

UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;

// Request notifications permission to enable chat notifications
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
}];

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"example"
Expand All @@ -50,6 +61,24 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
if ([response.notification.request.content.categoryIdentifier containsString:SHKNotificationCategoryIdentifierDomain]) {
[SHKShake reportNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
return;
}

completionHandler();
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
if ([notification.request.content.categoryIdentifier containsString:SHKNotificationCategoryIdentifierDomain]) {
[SHKShake reportNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
return;
}

completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
Expand Down

0 comments on commit 14041b2

Please sign in to comment.