Skip to content

Commit

Permalink
Merge pull request #25 from carnivalmobile/update-sdks
Browse files Browse the repository at this point in the history
Update sdks
  • Loading branch information
igstewart3 authored Feb 25, 2019
2 parents 2f9d527 + a970934 commit 3dcd2f6
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 23 deletions.
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.3.1'
}
}

Expand Down Expand Up @@ -48,7 +48,7 @@ repositories {

dependencies {
api 'com.facebook.react:react-native:+'
api 'com.carnival.sdk:carnival:6.3.1'
api 'com.carnival.sdk:carnival:7.0.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
Expand Down
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enabled for Android X
android.enableJetifier=true
android.useAndroidX=true
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.support.annotation.RequiresPermission;

import com.carnival.sdk.AttributeMap;
import com.carnival.sdk.Carnival;
import com.carnival.sdk.CarnivalImpressionType;
import com.carnival.sdk.ContentItem;
import com.carnival.sdk.Message;
import com.carnival.sdk.MessageActivity;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;

Expand All @@ -42,9 +38,7 @@
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.booleanThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.doNothing;
Expand All @@ -53,7 +47,6 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Carnival.class, RNCarnivalModule.class})
Expand Down
92 changes: 92 additions & 0 deletions ios/CarnivalSDKReactNativeTests/RNCarnivalTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import <XCTest/XCTest.h>
#import "RNCarnival.h"
#import "Kiwi.h"
#import <UserNotifications/UserNotifications.h>

// interface to expose methods for testing
@interface RNCarnival ()
Expand All @@ -28,6 +29,7 @@ -(void)trackPageview:(NSString *)url tags:(NSArray *)tags resolver:(RCTPromiseRe
-(void)trackImpression:(NSString *)sectionID url:(NSArray *)urls resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
-(void)setGeoIPTrackingEnabled:(BOOL)enabled;
-(void)setCrashHandlersEnabled:(BOOL)enabled;
-(void)registerForPushNotifications;
-(void)clearDevice:(NSInteger)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
-(void)setProfileVars:(NSDictionary *)vars resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
-(void)getProfileVars:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
Expand Down Expand Up @@ -749,6 +751,96 @@ + (void)setWrapperName:(NSString *)wrapperName andVersion:(NSString *)wrapperVer
[[check should] equal:error];
});
});

context(@"the registerForPushNotifications method", ^{
__block RNCarnival *rnCarnival = nil;
__block NSProcessInfo *mockInfo = nil;
__block UNAuthorizationOptions options = UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound;
__block NSOperationQueue *mockQueue;
beforeEach(^{
[Carnival stub:@selector(getProfileVarsWithResponse:)];
rnCarnival = [[RNCarnival alloc] initWithDisplayInAppNotifications:YES];

mockQueue = [NSOperationQueue mock];
[mockQueue stub:@selector(addOperationWithBlock:)];
[NSOperationQueue stub:@selector(mainQueue) andReturn:mockQueue];

NSOperatingSystemVersion version;
version.majorVersion = 10;
version.minorVersion = 0;
version.patchVersion = 0;

mockInfo = [NSProcessInfo mock];
[mockInfo stub:@selector(operatingSystemVersion) andReturn:theValue(version)];

[NSProcessInfo stub:@selector(processInfo) andReturn:mockInfo];
});

context(@"on iOS 10+", ^{
__block UNUserNotificationCenter *mockCenter;
beforeEach(^{
mockCenter = [UNUserNotificationCenter mock];
[UNUserNotificationCenter stub:@selector(currentNotificationCenter) andReturn:mockCenter];
});

it(@"should request authorization from the UNUserNotificationCenter", ^{
[[mockCenter should] receive:@selector(requestAuthorizationWithOptions:completionHandler:)];

[rnCarnival registerForPushNotifications];
});
});

context(@"on iOS 8-9", ^{
__block UIApplication *mockApplication;
beforeEach(^{
mockApplication = [UIApplication mock];
[UIApplication stub:@selector(sharedApplication) andReturn:mockApplication];

NSOperatingSystemVersion version;
version.majorVersion = 8;
version.minorVersion = 0;
version.patchVersion = 0;

mockInfo = [NSProcessInfo mock];
[mockInfo stub:@selector(operatingSystemVersion) andReturn:theValue(version)];

[NSProcessInfo stub:@selector(processInfo) andReturn:mockInfo];
});

it(@"should register user notification settings with UIApplication", ^{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationType)options categories:nil];
[[mockApplication should] receive:@selector(registerUserNotificationSettings:) withArguments:settings];

[rnCarnival registerForPushNotifications];
});
});

context(@"if application is not registered for remote notifications", ^{
__block UNUserNotificationCenter *mockCenter;
__block UIApplication *mockApplication;
beforeEach(^{
mockCenter = [UNUserNotificationCenter mock];
[mockCenter stub:@selector(requestAuthorizationWithOptions:completionHandler:)];
[UNUserNotificationCenter stub:@selector(currentNotificationCenter) andReturn:mockCenter];

mockApplication = [UIApplication mock];
[mockApplication stub:@selector(isRegisteredForRemoteNotifications) andReturn:theValue(NO)];
[UIApplication stub:@selector(sharedApplication) andReturn:mockApplication];


});

it(@"should register for remote notifications", ^{
[[mockApplication should] receive:@selector(registerForRemoteNotifications)];
KWCaptureSpy *queueCapture = [mockQueue captureArgument:@selector(addOperationWithBlock:) atIndex:0];

[rnCarnival registerForPushNotifications];

void (^opBlock)(void) = queueCapture.argument;
opBlock();
});
});
});
});

SPEC_END
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ target 'CarnivalSDKReactNative' do
'CxxBridge' # Include this for RN >= 0.47
]

pod 'Carnival', '8.1.0'
pod 'Carnival', '8.2.0'
pod 'Kiwi', '2.4.0'
pod 'OCMock', '3.1.2'

Expand Down
8 changes: 4 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- boost-for-react-native (1.63.0)
- Carnival (8.1.0)
- Carnival (8.2.0)
- DoubleConversion (1.1.5)
- Folly (2016.10.31.00):
- boost-for-react-native
Expand Down Expand Up @@ -28,7 +28,7 @@ PODS:
- yoga (0.56.0.React)

DEPENDENCIES:
- Carnival (= 8.1.0)
- Carnival (= 8.2.0)
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
- Kiwi (= 2.4.0)
- OCMock (= 3.1.2)
Expand All @@ -55,7 +55,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
Carnival: 5d879c99f730e58d4927841c1aa5215b8433747e
Carnival: d54ea7ff27498325bfbafe3be64a6314545ad110
DoubleConversion: e22e0762848812a87afd67ffda3998d9ef29170c
Folly: c89ac2d5c6ab169cd7397ef27485c44f35f742c7
glog: 1de0bb937dccdc981596d3b5825ebfb765017ded
Expand All @@ -64,6 +64,6 @@ SPEC CHECKSUMS:
React: 1fe0eb13d90b625d94c3b117c274dcfd2e760e11
yoga: b1ce48b6cf950b98deae82838f5173ea7cf89e85

PODFILE CHECKSUM: 004c3df16510cd58e64423f5409105223a3b9a36
PODFILE CHECKSUM: 739b2089049ddbf50911da0dda25eaf52b689dc7

COCOAPODS: 1.5.3
21 changes: 13 additions & 8 deletions ios/RNCarnival.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#import "RNCarnival.h"
#import <UserNotifications/UserNotifications.h>

@interface CarnivalMessage ()

Expand Down Expand Up @@ -336,16 +337,20 @@ - (BOOL)shouldPresentInAppNotificationForMessage:(CarnivalMessage *)message {

// Push Registration
RCT_EXPORT_METHOD(registerForPushNotifications) {
UIUserNotificationType types = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound;

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { // iOS 8+
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
UNAuthorizationOptions options = UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound;
if ([[NSProcessInfo processInfo] operatingSystemVersion].majorVersion >= 10) {
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error) {}];
}
else { //iOS 7
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)types];
else {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationType)options categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if(![[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
}

RCT_EXPORT_METHOD(clearDevice:(NSInteger)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
Expand Down

0 comments on commit 3dcd2f6

Please sign in to comment.