Skip to content

Commit 85318ed

Browse files
Push notification handle push delegate explicitly (#113)
* Push notification handle push delegate explicitly -- Exclude push notification macro added for RN code. * SDK version updated to 22.06.5 * Forwarding push callbacks to appdelegate Removed "COUNTLY_NOT_SET_PUSH_DELEGATE" flag * Update CountlyPushNotifications.m * Changelog updated * Update CHANGELOG.md Co-authored-by: ArtursKadikis <[email protected]>
1 parent 25e7833 commit 85318ed

File tree

9 files changed

+56
-16
lines changed

9 files changed

+56
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 22.06.5
2+
* Added COUNTLY_EXCLUDE_PUSHNOTIFICATIONS flag in iOS React Native side to disable push notifications altogether.
3+
* Forwarding push callbacks to appDelegate if CountlyRNPushNotifications.m is acting as push notification delegate.
4+
* Underlying android SDK version is 22.06.2
5+
* Underlying iOS SDK version is 22.06.2
6+
17
## 22.06.4
28
* Fixed incorrect iOS push token type when passing "Countly.messagingMode.PRODUCTION" as token type.
39
* Underlying android SDK version is 22.06.2

CountlyReactNative.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'CountlyReactNative'
3-
s.version = '22.06.4'
3+
s.version = '22.06.5'
44
s.license = {
55
:type => 'COMMUNITY',
66
:text => <<-LICENSE
@@ -34,7 +34,7 @@ Pod::Spec.new do |s|
3434
s.author = {'Countly' => '[email protected]'}
3535
s.source = { :git => 'https://github.com/Countly/countly-sdk-ios.git', :tag => s.version.to_s }
3636
s.source_files = 'ios/src/*.{h,m}'
37-
s.public_header_files = 'ios/src/CountlyReactNative.h'
37+
s.public_header_files = 'ios/src/CountlyReactNative.h, ios/src/CountlyPushNotifications.h'
3838
s.requires_arc = true
3939
s.ios.deployment_target = '10.0'
4040
s.osx.deployment_target = '10.14'

android/src/main/java/ly/count/android/sdk/react/CountlyReactNative.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public String toString(){
8181
public class CountlyReactNative extends ReactContextBaseJavaModule implements LifecycleEventListener {
8282

8383
public static final String TAG = "CountlyRNPlugin";
84-
private String COUNTLY_RN_SDK_VERSION_STRING = "22.06.4";
84+
private String COUNTLY_RN_SDK_VERSION_STRING = "22.06.5";
8585
private String COUNTLY_RN_SDK_NAME = "js-rnb-android";
8686

8787
private static final CountlyConfig config = new CountlyConfig();

example/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rm App.js
1111
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/App.js --output App.js
1212
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/Example.js --output Example.js
1313

14-
14+
1515

1616
cd ./ios
1717
pod install

ios/src/CountlyRNPushNotifications.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@interface CountlyRNPushNotifications : NSObject
12-
12+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
1313
+ (instancetype _Nonnull )sharedInstance;
1414

1515
- (void)startObservingNotifications;
@@ -20,4 +20,5 @@
2020
- (void)setCountlyReactNative:(CountlyReactNative *_Nullable)countlyReactNative;
2121
- (void)onNotification:(NSDictionary *_Nullable)notification;
2222
- (void)onNotificationResponse:(UNNotificationResponse* _Nullable)response;
23+
#endif
2324
@end

ios/src/CountlyRNPushNotifications.m

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#import "UserNotifications/UserNotifications.h"
99
#import "CountlyCommon.h"
1010

11-
11+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
1212
NSDictionary *lastStoredNotification = nil;
1313
Result notificationListener = nil;
1414
NSMutableArray *notifications = nil;
@@ -19,12 +19,12 @@
1919
typedef NSString* CLYUserDefaultKey NS_EXTENSIBLE_STRING_ENUM;
2020
CLYUserDefaultKey const CLYPushNotificationsKey = @"notificationsKey";
2121
CLYUserDefaultKey const CLYPushButtonIndexKey = @"notificationBtnIndexKey";
22-
22+
#endif
2323
@interface CountlyRNPushNotifications () <UNUserNotificationCenterDelegate>
2424
@end
2525

2626
@implementation CountlyRNPushNotifications
27-
27+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
2828
+ (instancetype)sharedInstance
2929
{
3030
static CountlyRNPushNotifications* s_sharedInstance;
@@ -137,7 +137,12 @@ - (void)openURL:(NSString *)URLString
137137
// when user open the app by tapping notification in any state.
138138
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{
139139
[self onNotificationResponse: response];
140-
completionHandler();
140+
141+
id<UNUserNotificationCenterDelegate> appDelegate = (id<UNUserNotificationCenterDelegate>)UIApplication.sharedApplication.delegate;
142+
if ([appDelegate respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)])
143+
[appDelegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
144+
else
145+
completionHandler();
141146
}
142147

143148
// When app is running and notification received
@@ -162,7 +167,13 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNot
162167
}
163168
completionHandler(presentationOption);
164169
}
165-
completionHandler(UNNotificationPresentationOptionNone);
170+
171+
id<UNUserNotificationCenterDelegate> appDelegate = (id<UNUserNotificationCenterDelegate>)UIApplication.sharedApplication.delegate;
172+
173+
if ([appDelegate respondsToSelector:@selector(userNotificationCenter:willPresentNotification:withCompletionHandler:)])
174+
[appDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
175+
else
176+
completionHandler(UNNotificationPresentationOptionNone);
166177
}
167178

168179
- (void)onNotification:(NSDictionary *)notificationMessage
@@ -209,5 +220,6 @@ + (NSString *) toJSON: (NSDictionary *) json{
209220
return jsonString;
210221
}
211222
}
223+
#endif
212224

213225
@end

ios/src/CountlyReactNative.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ typedef void (^Result)(id _Nullable result);
5555
- (void)recordAttributionID:(NSArray*_Nullable)arguments;
5656
- (void)appLoadingFinished;
5757
- (void)disablePushNotifications;
58-
- (void)notificationCallback:(NSString*_Nullable)notificationJson;
5958

59+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
60+
- (void)notificationCallback:(NSString*_Nullable)notificationJson;
6061
+ (void)startObservingNotifications;
6162
+ (void)onNotification:(NSDictionary *_Nullable)notification;
6263
+ (void)onNotificationResponse:(UNNotificationResponse* _Nullable)response;
64+
#endif
6365
@end

ios/src/CountlyReactNative.m

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
#import "Countly.h"
77
#import "CountlyReactNative.h"
88
#import "CountlyConfig.h"
9-
#import "CountlyPushNotifications.h"
109
#import "CountlyConnectionManager.h"
1110
#import "CountlyRemoteConfig.h"
1211
#import "CountlyCommon.h"
12+
13+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
1314
#import "CountlyRNPushNotifications.h"
15+
#endif
1416

1517
#if DEBUG
1618
#define COUNTLY_RN_LOG(fmt, ...) CountlyRNInternalLog(fmt, ##__VA_ARGS__)
@@ -22,7 +24,7 @@ @interface CountlyFeedbackWidget ()
2224
+ (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary;
2325
@end
2426

25-
NSString* const kCountlyReactNativeSDKVersion = @"22.06.4";
27+
NSString* const kCountlyReactNativeSDKVersion = @"22.06.5";
2628
NSString* const kCountlyReactNativeSDKName = @"js-rnb-ios";
2729

2830
CLYPushTestMode const CLYPushTestModeProduction = @"CLYPushTestModeProduction";
@@ -57,7 +59,9 @@ - (instancetype)init
5759

5860
}
5961

62+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
6063
[CountlyRNPushNotifications.sharedInstance setCountlyReactNative:self];
64+
#endif
6165

6266
return self;
6367
}
@@ -89,15 +93,19 @@ - (instancetype)init
8993

9094
CountlyCommon.sharedInstance.SDKName = kCountlyReactNativeSDKName;
9195
CountlyCommon.sharedInstance.SDKVersion = kCountlyReactNativeSDKVersion;
96+
97+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
9298
if(enablePushNotifications) {
9399
[self addCountlyFeature:CLYPushNotifications];
94100
}
95-
101+
#endif
96102
if (serverurl != nil && [serverurl length] > 0) {
97103
dispatch_async(dispatch_get_main_queue(), ^
98104
{
99105
[[Countly sharedInstance] startWithConfig:config];
106+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
100107
[CountlyRNPushNotifications.sharedInstance recordPushActions];
108+
#endif
101109
resolve(@"Success");
102110
});
103111
}
@@ -194,13 +202,16 @@ - (instancetype)init
194202

195203
RCT_EXPORT_METHOD(disablePushNotifications)
196204
{
205+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
197206
dispatch_async(dispatch_get_main_queue(), ^ {
198207
enablePushNotifications = false;
199208
});
209+
#endif
200210
}
201211

202212
RCT_EXPORT_METHOD(sendPushToken:(NSArray*)arguments)
203213
{
214+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
204215
dispatch_async(dispatch_get_main_queue(), ^ {
205216

206217
NSString* token = [arguments objectAtIndex:0];
@@ -213,16 +224,17 @@ - (instancetype)init
213224
[request setHTTPMethod:@"GET"];
214225
[request setURL:[NSURL URLWithString:urlString]];
215226
});
227+
#endif
216228
}
217229
RCT_EXPORT_METHOD(pushTokenType:(NSArray*)arguments)
218230
{
231+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
219232
dispatch_async(dispatch_get_main_queue(), ^ {
220233
if (config == nil){
221234
config = CountlyConfig.new;
222235
}
223236
config.sendPushTokenAlways = YES;
224237
config.pushTestMode = CLYPushTestModeProduction;
225-
226238
NSString* tokenType = [arguments objectAtIndex:0];
227239
if([tokenType isEqualToString: @"1"]){
228240
config.pushTestMode = CLYPushTestModeDevelopment;
@@ -233,18 +245,24 @@ - (instancetype)init
233245

234246
CountlyPushNotifications.sharedInstance.pushTestMode = config.pushTestMode;
235247
});
248+
#endif
236249
}
237250

238251
RCT_EXPORT_METHOD(askForNotificationPermission:(NSArray*)arguments)
239252
{
253+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
240254
[CountlyRNPushNotifications.sharedInstance askForNotificationPermission];
255+
#endif
241256
}
242257
RCT_EXPORT_METHOD(registerForNotification:(NSArray*)arguments)
243258
{
259+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
244260
[CountlyRNPushNotifications.sharedInstance registerForNotification];
261+
#endif
245262

246263
};
247264

265+
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
248266
- (void)notificationCallback:(NSString*_Nullable)notificationJson {
249267
[self sendEventWithName:pushNotificationCallbackName body: notificationJson];
250268
}
@@ -260,6 +278,7 @@ + (void)onNotification:(NSDictionary *_Nullable)notification {
260278
+ (void)onNotificationResponse:(UNNotificationResponse* _Nullable)response {
261279
[CountlyRNPushNotifications.sharedInstance onNotificationResponse:response];
262280
}
281+
#endif
263282

264283
+ (void) log: (NSString *) theMessage{
265284
if(config.enableDebug == YES){

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "countly-sdk-react-native-bridge",
3-
"version": "22.06.4",
3+
"version": "22.06.5",
44
"author": "Countly <[email protected]> (https://count.ly/)",
55
"bugs": {
66
"url": "https://github.com/Countly/countly-sdk-react-native-bridge/issues"

0 commit comments

Comments
 (0)