Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
[SDK-636] : Disable push notifications for iOS (#91)
Browse files Browse the repository at this point in the history
* — COUNTLY_EXCLUDE_PUSHNOTIFICATIONS added to disable push notifications
— SDK version updated to 20.11.3
— underlying iOS sdk version updated to 20.11.3
— Changlelog updated.

* Changelog updated for SDK-637

* Typo fixes

* Code Indentation fixes

* Updated underlying android SDK to 20.11.11
  • Loading branch information
ijunaid authored Jan 20, 2022
1 parent f6416fb commit 618ee2f
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
countly:[email protected].2
countly:[email protected].3
[email protected]
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 20.11.3
* Added COUNTLY_EXCLUDE_PUSHNOTIFICATIONS flag to disable push notifications altogether in order to avoid App Store Connect warnings.
* Fixed issues related to Push notification crash when notification recieved from other SDK's/Plugins (not from Countly).
* Updated underlying android SDK to 20.11.11
* Updated underlying iOS SDK version to 20.11.3

## 20.11.2
* Moving a push related broadcast receiver declaration to the manifest to comply with 'PendingIntent' checks
* Updated underlying android SDK to 20.11.9
Expand Down
2 changes: 1 addition & 1 deletion Countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Countly = {};
Countly.serverUrl = "";
Countly.appKey = "";
Countly.ready = false;
Countly.version = "20.11.2";
Countly.version = "20.11.3";
Countly.isDebug = false;
Countly.isInitCalled = false;
if (window.cordova.platformId == "android") {
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'countly:countly-sdk-js',
version: '20.11.2',
version: '20.11.3',
summary: 'Countly is an innovative, real-time, open source mobile analytics and push notifications platform. It collects data from mobile devices, and visualizes this information to analyze mobile application usage and end-user behavior. There are two parts of Countly: the server that collects and analyzes data, and mobile SDK that sends this data. Both parts are open source with different licensing terms.',
git: 'https://github.com/Countly/countly-sdk-cordova.git',
documentation: 'README.md'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "countly-sdk-js",
"version": "20.11.2",
"version": "20.11.3",
"description": "Countly is an innovative, real-time, open source mobile analytics and push notifications platform. It collects data from mobile devices, and visualizes this information to analyze mobile application usage and end-user behavior. There are two parts of Countly: the server that collects and analyzes data, and mobile SDK that sends this data. Both parts are open source with different licensing terms.",
"cordova": {
"id": "countly-sdk-js",
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="countly-sdk-cordova" version="20.11.2">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="countly-sdk-cordova" version="20.11.3">

<name>Countly Cordova SDK</name>

Expand Down Expand Up @@ -141,7 +141,7 @@

<source-file src="src/android/CountlyCordova.java" target-dir="src/ly/count/android/sdk"/>
<source-file src="src/android/CountlyNative.java" target-dir="src/ly/count/android/sdk"/>
<framework src="ly.count.android:sdk:20.11.9" />
<framework src="ly.count.android:sdk:20.11.11" />

<!-- Push notification -->
<config-file target="AndroidManifest.xml" parent="/manifest/application">
Expand Down
2 changes: 1 addition & 1 deletion src/android/CountlyNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class CountlyNative {

public static final String TAG = "CountlyCordovaPlugin";
private String COUNTLY_CORDOVA_SDK_VERSION_STRING = "20.11.2";
private String COUNTLY_CORDOVA_SDK_VERSION_STRING = "20.11.3";
private String COUNTLY_CORDOVA_SDK_NAME = "js-cordovab-android";

private Countly.CountlyMessagingMode pushTokenTypeVariable = Countly.CountlyMessagingMode.PRODUCTION;
Expand Down
28 changes: 23 additions & 5 deletions src/ios/CountlyNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Boolean isInitialized = false;
NSString *const pushPluginApplicationDidBecomeActiveNotification = @"pushPluginApplicationDidBecomeActiveNotification";

NSString* const kCountlyCordovaSDKVersion = @"20.11.2";
NSString* const kCountlyCordovaSDKVersion = @"20.11.3";
NSString* const kCountlyCordovaSDKName = @"js-cordovab-ios";

@interface CountlyFeedbackWidget ()
Expand Down Expand Up @@ -70,8 +70,9 @@ + (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{

#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
Class class = [self class];

SEL originalSelector = @selector(init);
SEL swizzledSelector = @selector(pushPluginSwizzledInit);

Expand All @@ -92,9 +93,11 @@ + (void)load
} else {
method_exchangeImplementations(original, swizzled);
}
#endif
});
}

#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
- (AppDelegate *)pushPluginSwizzledInit
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
Expand Down Expand Up @@ -209,6 +212,7 @@ - (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification {
[CountlyNative onNotification: self.launchNotification];
[[NSNotificationCenter defaultCenter] postNotificationName:pushPluginApplicationDidBecomeActiveNotification object:nil];
}
#endif
@end


Expand All @@ -223,6 +227,7 @@ @implementation CountlyNative
CountlyConfig* config = nil;
Boolean isDebug = false;

#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
+ (void)onNotification: (NSDictionary *) notificationMessage{
if(!notificationMessage) {
COUNTLY_CORDOVA_LOG(@"onNotification, Notification received. No valid message");
Expand Down Expand Up @@ -269,6 +274,7 @@ - (void)recordPushAction
}
[notificationIDs removeAllObjects];
}
#endif

- (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Result) result{
if(isDebug == true){
Expand All @@ -293,7 +299,9 @@ - (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Re
CountlyCommon.sharedInstance.SDKVersion = kCountlyCordovaSDKVersion;

Countly.sharedInstance.isAutoViewTrackingActive = NO;
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
[self addCountlyFeature:CLYPushNotifications];
#endif

if(command.count == 3){
deviceID = [command objectAtIndex:2];
Expand All @@ -304,7 +312,10 @@ - (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Re
dispatch_async(dispatch_get_main_queue(), ^ {
isInitialized = true;
[[Countly sharedInstance] startWithConfig:config];

#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
[self recordPushAction];
#endif
});
result(@"initialized.");
} else {
Expand Down Expand Up @@ -614,6 +625,7 @@ - (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Re
});

}else if ([@"sendPushToken" isEqualToString:method]) {
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
if(config != nil){
NSString* token = [command objectAtIndex:0];
int messagingMode = 1;
Expand All @@ -625,22 +637,29 @@ - (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Re
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:urlString]];
}
#endif
result(@"sendPushToken!");

}else if ([@"askForNotificationPermission" isEqualToString:method]) {
dispatch_async(dispatch_get_main_queue(), ^ {
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
[Countly.sharedInstance askForNotificationPermission];
#endif
result(@"askForNotificationPermission!");
});
}else if ([@"registerForNotification" isEqualToString:method]) {
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
COUNTLY_CORDOVA_LOG(@"registerForNotification");
notificationListener = result;
if(lastStoredNotification != nil){
result([lastStoredNotification description]);
lastStoredNotification = nil;
}
#endif
}else if ([@"pushTokenType" isEqualToString:method]) {

dispatch_async(dispatch_get_main_queue(), ^ {
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
NSString* tokenType = [command objectAtIndex:0];
if([tokenType isEqualToString: @"1"]){
config.pushTestMode = @"CLYPushTestModeDevelopment";
Expand All @@ -649,6 +668,7 @@ - (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Re
config.pushTestMode = @"CLYPushTestModeTestFlightOrAdHoc";
}else{
}
#endif
result(@"pushTokenType!");
});
}else if ([@"userData_setProperty" isEqualToString:method]) {
Expand Down Expand Up @@ -1106,6 +1126,4 @@ void CountlyCordovaInternalLog(NSString *format, ...)
va_end(args);
}

@end


@end
1 change: 1 addition & 0 deletions src/ios/CountlyiOS/CountlyCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void CountlyPrint(NSString *stringToPrint);
#if (TARGET_OS_IOS || TARGET_OS_TV)
- (UIViewController *)topViewController;
- (void)tryPresentingViewController:(UIViewController *)viewController;
- (void)tryPresentingViewController:(UIViewController *)viewController withCompletion:(void (^ __nullable) (void))completion;
#endif

- (void)startAppleWatchMatching;
Expand Down
19 changes: 16 additions & 3 deletions src/ios/CountlyiOS/CountlyCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ @interface CountlyCommon ()
#endif
@end

NSString* const kCountlySDKVersion = @"20.11.2";
NSString* const kCountlySDKVersion = @"20.11.3";
NSString* const kCountlySDKName = @"objc-native-ios";

NSString* const kCountlyParentDeviceIDTransferKey = @"kCountlyParentDeviceIDTransferKey";
Expand Down Expand Up @@ -301,16 +301,29 @@ - (UIViewController *)topViewController
}

- (void)tryPresentingViewController:(UIViewController *)viewController
{
[self tryPresentingViewController:viewController withCompletion:nil];
}

- (void)tryPresentingViewController:(UIViewController *)viewController withCompletion:(void (^ __nullable) (void))completion
{
UIViewController* topVC = self.topViewController;

if (topVC)
{
[topVC presentViewController:viewController animated:YES completion:nil];
[topVC presentViewController:viewController animated:YES completion:^
{
if (completion)
completion();
}];

return;
}

[self performSelector:@selector(tryPresentingViewController:) withObject:viewController afterDelay:1.0];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
{
[self tryPresentingViewController:viewController];
});
}
#endif

Expand Down
3 changes: 3 additions & 0 deletions src/ios/CountlyiOS/CountlyConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ extern NSString* const kCountlyEndpointO;
extern NSString* const kCountlyEndpointSDK;
extern NSString* const kCountlyEndpointFeedback;
extern NSString* const kCountlyEndpointWidget;
extern NSString* const kCountlyEndpointSurveys;

extern const NSInteger kCountlyGETRequestMaxLength;

@interface CountlyConnectionManager : NSObject <NSURLSessionDelegate>

Expand Down
1 change: 1 addition & 0 deletions src/ios/CountlyiOS/CountlyConnectionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ @interface CountlyConnectionManager ()
NSString* const kCountlyEndpointSDK = @"/sdk";
NSString* const kCountlyEndpointFeedback = @"/feedback";
NSString* const kCountlyEndpointWidget = @"/widget";
NSString* const kCountlyEndpointSurveys = @"/surveys";

const NSInteger kCountlyGETRequestMaxLength = 2048;

Expand Down
27 changes: 26 additions & 1 deletion src/ios/CountlyiOS/CountlyFeedbackWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern CLYFeedbackWidgetType const CLYFeedbackWidgetTypeNPS;
@property (nonatomic, readonly) CLYFeedbackWidgetType type;
@property (nonatomic, readonly) NSString* ID;
@property (nonatomic, readonly) NSString* name;

@property (nonatomic, readonly) NSDictionary* data;

/**
* Modally presents the feedback widget above the top visible view controller.
Expand All @@ -28,6 +28,31 @@ extern CLYFeedbackWidgetType const CLYFeedbackWidgetTypeNPS;
*/
- (void)present;

/**
* Modally presents the feedback widget above the top visible view controller and executes given blocks.
* @discussion Calls to this method will be ignored if consent for @c CLYConsentFeedback is not given while @c requiresConsent flag is set on initial configuration.
* @param appearBlock Block to be executed when widget is displayed
* @param dismissBlock Block to be executed when widget is dismissed
*/
- (void)presentWithAppearBlock:(void(^ __nullable)(void))appearBlock andDismissBlock:(void(^ __nullable)(void))dismissBlock;

/**
* Fetches feedback widget's data to be used for manually presenting it.
* @discussion When feedback widget's data is fetched successfully, @c completionHandler will be executed with an @c NSDictionary
* @discussion This @c NSDictionary represents the feedback widget's data and can be used for creating custom feedback widget UI.
* @discussion Otherwise, @c completionHandler will be executed with an @c NSError.
* @param completionHandler A completion handler block to be executed when data is fetched successfully or there is an error
*/
- (void)getWidgetData:(void (^)(NSDictionary * __nullable widgetData, NSError * __nullable error))completionHandler;

/**
* Records manually presented feedback widget's result.
* @discussion Calls to this method will be ignored if consent for @c CLYConsentFeedback is not given while @c requiresConsent flag is set on initial configuration.
* @discussion If there is no result available due to user dismissing the feedback widget without completing it, @c result can be passed as @c nil.
* @param result A dictionary representing result of manually presented feedback widget
*/
- (void)recordResult:(NSDictionary * __nullable)result;

#endif
@end

Expand Down
Loading

0 comments on commit 618ee2f

Please sign in to comment.