Skip to content

Commit

Permalink
Updating Unity plugins for version 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
radixdev committed Jun 23, 2021
1 parent d450b90 commit 337bf0c
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 6 deletions.
Binary file modified Assets/Plugins/Android/appboy-unity.aar
Binary file not shown.
34 changes: 34 additions & 0 deletions Assets/Plugins/Appboy/AppboyBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ public enum BrazeUnityMessageType {
CONTENT_CARDS_UPDATED = 7
}

public enum BrazeUnityInAppMessageDisplayActionType {
/// <summary>
/// Sets In-App Messages to display immediately when triggered.
/// </summary>
IAM_DISPLAY_NOW = 0,
/// <summary>
/// Sets In-App Messages to display at a later time and be saved in a stack.
/// </summary>
IAM_DISPLAY_LATER = 1,
/// <summary>
/// Sets In-App Messages to be discarded after being triggered.
/// </summary>
IAM_DISCARD = 2,
// TODO - Blocked by SDK-1596
// /// <summary>
// /// Requests that any In-App Message previously saved to a stack to be displayed immediately.
// /// </summary>
// REQUEST_IAM_DISPLAY = 3
}

public delegate void PushPromptResponseReceived(bool granted);
public delegate void PushTokenReceivedFromSystem(string token);

Expand All @@ -86,6 +106,8 @@ public static BrazePlatform mBinding {
return new BrazeAndroidPlatform();
#elif UNITY_IOS
return new BrazeiOSPlatform();
#else
return null;
#endif
}
}
Expand Down Expand Up @@ -598,5 +620,17 @@ public static void ConfigureListener(BrazeUnityMessageType messageType, string g
mBinding.ConfigureListener(messageType, gameobject, method);
#endif
}

public static void SetInAppMessageDisplayAction(BrazeUnityInAppMessageDisplayActionType actionType) {
#if HAS_BRAZE_SDK
mBinding.SetInAppMessageDisplayAction(actionType);
#endif
}

public static void DisplayContentCards() {
#if HAS_BRAZE_SDK
mBinding.DisplayContentCards();
#endif
}
}
}
8 changes: 8 additions & 0 deletions Assets/Plugins/Appboy/BrazeAndroidPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@ public void AddAlias(string alias, string label) {
public void ConfigureListener(BrazeUnityMessageType messageType, string gameobject, string method) {
UnityConfigurationProvider.Call("configureListener", (int)messageType, gameobject, method);
}

public void SetInAppMessageDisplayAction(BrazeUnityInAppMessageDisplayActionType actionType) {
AppboyUnityActivity.Call("onNewUnityInAppMessageManagerAction", (int)actionType);
}

public void DisplayContentCards() {
AppboyUnityActivity.Call("launchContentCardsActivity");
}
}

#endif
2 changes: 2 additions & 0 deletions Assets/Plugins/Appboy/BrazePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ string profileImageUrl
void RequestImmediateDataFlush();
void AddAlias(string alias, string label);
void ConfigureListener(BrazeUnityMessageType messageType, string gameobject, string method);
void SetInAppMessageDisplayAction(BrazeUnityInAppMessageDisplayActionType actionType);
void DisplayContentCards();
}
14 changes: 14 additions & 0 deletions Assets/Plugins/Appboy/BrazeiOSPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public class BrazeiOSPlatform : BrazePlatform {
[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void _setUserTwitterData(int twitterUserId, string twitterHandle, string name, string description, int followerCount, int followingCount, int tweetCount, string profileImageUrl);

[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void _setInAppMessageDisplayAction(int actionType);

[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void _logInAppMessageClicked(string inAppMessageJSONString);

Expand Down Expand Up @@ -131,6 +134,9 @@ public class BrazeiOSPlatform : BrazePlatform {
[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void _requestContentCardsRefreshFromCache();

[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void _displayContentCards();

[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void _logContentCardsDisplayed();

Expand Down Expand Up @@ -299,6 +305,10 @@ public void DisplayNextInAppMessage(bool withDelegate) {
_displayNextInAppMessage(withDelegate);
}

public void SetInAppMessageDisplayAction(BrazeUnityInAppMessageDisplayActionType actionType) {
_setInAppMessageDisplayAction((int)actionType);
}

public void LogInAppMessageClicked(string inAppMessageJSONString) {
_logInAppMessageClicked(inAppMessageJSONString);
}
Expand Down Expand Up @@ -351,6 +361,10 @@ public void RequestContentCardsRefreshFromCache() {
_requestContentCardsRefreshFromCache();
}

public void DisplayContentCards() {
_displayContentCards();
}

public void LogContentCardsDisplayed() {
_logContentCardsDisplayed();
}
Expand Down
8 changes: 8 additions & 0 deletions Assets/Plugins/iOS/AppboyBinding.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ void _displayNextInAppMessage(bool withDelegate) {
[[AppboyUnityManager sharedInstance] displayNextInAppMessageWithDelegate:withDelegate];
}

void _setInAppMessageDisplayAction(int actionType) {
[[AppboyUnityManager sharedInstance] setInAppMessageDisplayAction:actionType];
}

# pragma mark - News Feed analytics

void _logCardImpression(const char* cardJSONString) {
Expand Down Expand Up @@ -256,6 +260,10 @@ void _logContentCardDismissed(const char* cardJSONString) {
[[AppboyUnityManager sharedInstance] logContentCardDismissed:GetStringParam(cardJSONString)];
}

void _displayContentCards() {
[[AppboyUnityManager sharedInstance] displayContentCards];
}

void _logContentCardsDisplayed() {
[[Appboy sharedInstance] logContentCardsDisplayed];
}
Expand Down
13 changes: 13 additions & 0 deletions Assets/Plugins/iOS/AppboyUnityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ typedef NS_ENUM(NSInteger, ABKUnityMessageType) {
ABKContentCardsUpdated = 7
};

/**
* These must correspond 1:1 to BrazeUnityInAppMessageDisplayActionType in AppboyBinding.cs.
*/
typedef NS_ENUM(NSInteger, ABKUnityInAppMessageDisplayActionType) {
ABKIAMDisplayNow = 0,
ABKIAMDisplayLater = 1,
ABKIAMDiscard = 2,
ABKIAMRequestIAMDisplay = 3
};

@interface AppboyUnityManager : NSObject <ABKInAppMessageControllerDelegate, UNUserNotificationCenterDelegate>

@property (nonatomic,copy) NSDictionary *appboyUnityPlist;
Expand All @@ -51,6 +61,7 @@ typedef NS_ENUM(NSInteger, ABKUnityMessageType) {
@property (nonatomic, copy) NSString *unityPushTokenReceivedFromSystemFunctionName;
@property (nonatomic) BOOL sendInternalPushPermissionsPromptResponse;
@property (nonatomic) BOOL sendPushTokenReceivedFromSystem;
@property (nonatomic) ABKInAppMessageDisplayChoice displayAction;

+ (AppboyUnityManager *) sharedInstance;
- (NSString *)getApiKeyFromUnity;
Expand All @@ -65,6 +76,7 @@ typedef NS_ENUM(NSInteger, ABKUnityMessageType) {
- (void)logInAppMessageClicked:(NSString *)inAppMessageJSONString;
- (void)logInAppMessageButtonClicked:(NSString *)inAppMessageJSONString withButtonID:(NSInteger)buttonID;
- (void)displayNextInAppMessageWithDelegate:(BOOL)withDelegate;
- (void)setInAppMessageDisplayAction:(int)actionType;

// News Feed
- (void)logCardImpression:(NSString *)cardJSONString;
Expand All @@ -78,6 +90,7 @@ typedef NS_ENUM(NSInteger, ABKUnityMessageType) {
- (void)logContentCardDismissed:(NSString *)cardJSONString;
- (void)requestContentCardsRefresh;
- (void)requestContentCardsFromCache:(NSNotification *)notification;
- (void)displayContentCards;

/*!
* @discussion Passes the device token to Braze. The caller is responsible for respecting
Expand Down
58 changes: 52 additions & 6 deletions Assets/Plugins/iOS/AppboyUnityManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#import <Appboy_iOS_SDK/ABKCard.h>
#import <Appboy_iOS_SDK/ABKFacebookUser.h>
#import <Appboy_iOS_SDK/ABKTwitterUser.h>
#import <Appboy_iOS_SDK/ABKContentCardsViewController.h>
#import <Appboy_iOS_SDK/ABKUIUtils.h>

static NSString *const ABKInternalCallback = @"BrazeInternalCallback";
static NSString *const ABKInternalPushPermissionsPromptResponse = @"onPushPromptResponseReceived";
Expand Down Expand Up @@ -31,6 +33,16 @@ + (AppboyUnityManager*)sharedInstance {
return sharedInstance;
}

# pragma mark - Init

- (instancetype)init {
self = [super init];
if (self) {
self.displayAction = ABKDisplayInAppMessageNow;
}
return self;
}

# pragma mark - Config

- (NSString *)getApiKeyFromUnity {
Expand Down Expand Up @@ -120,13 +132,39 @@ - (void)getInAppMessageFromString:(NSString *)inAppMessageJSONString withInAppMe
# pragma mark - In-app message display

- (void)displayNextInAppMessageWithDelegate:(BOOL)withDelegate {
ABKInAppMessageController *delegate = nil;
id<ABKInAppMessageControllerDelegate> delegate = nil;
if (withDelegate) {
delegate = [Appboy sharedInstance].inAppMessageController.delegate;
}
[[Appboy sharedInstance].inAppMessageController displayNextInAppMessageWithDelegate:delegate];
}

- (void)setInAppMessageDisplayAction:(int)actionType {
[Appboy sharedInstance].inAppMessageController.delegate = self;
switch ((ABKUnityInAppMessageDisplayActionType)actionType) {
case ABKIAMDisplayNow:
NSLog(@"Setting in-app message display action to ABKDisplayInAppMessageNow.");
self.displayAction = ABKDisplayInAppMessageNow;
break;
case ABKIAMDisplayLater:
NSLog(@"Setting in-app message display action to ABKDisplayInAppMessageLater.");
self.displayAction = ABKDisplayInAppMessageLater;
break;
case ABKIAMDiscard:
NSLog(@"Setting in-app message display action to ABKIAMDiscard.");
self.displayAction = ABKDiscardInAppMessage;
break;
case ABKIAMRequestIAMDisplay:
// FIXME: Blocked by SDK-1596
NSLog(@"Requesting in-app message display (currently unimplemented).");
// [[Appboy sharedInstance].inAppMessageController displayNextInAppMessageWithDelegate:nil];
break;
default:
NSLog(@"Unknown in-app message display action type received.");
return;
}
}

# pragma mark - News Feed analytics

- (void)logCardImpression:(NSString *)cardJSONString {
Expand Down Expand Up @@ -267,6 +305,15 @@ - (void)requestContentCardsFromCache:(NSNotification *)notification {
[self unitySendMessageTo:self.unityContentCardsGameObjectName withMethod:self.unityContentCardsCallbackFunctionName withMessage:contentCardsString];
}

# pragma mark - Content Card UI

- (void)displayContentCards {
ABKContentCardsViewController *contentCards = [[ABKContentCardsViewController alloc] init];
[ABKUIUtils.activeApplicationViewController presentViewController:contentCards
animated:YES
completion:nil];
}

# pragma mark - Push

- (void)registerPushToken:(NSData *)data {
Expand Down Expand Up @@ -493,17 +540,16 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
*/
- (ABKInAppMessageDisplayChoice)beforeInAppMessageDisplayed:(ABKInAppMessage *)inAppMessage {
if (self.unityInAppMessageCallbackFunctionName == nil || self.unityInAppMessageGameObjectName == nil) {
NSLog(@"No properly configured game object for in-app messages. Returning ABKDisplayInAppMessageNow.",
self.unityInAppMessageGameObjectName);
return ABKDisplayInAppMessageNow;
NSLog(@"No properly configured game object for in-app messages. Using display action: %ld.", (long)self.displayAction);
return self.displayAction;
}

NSData *inAppMessageData = [inAppMessage serializeToData];
NSString *dataString = [[NSString alloc] initWithData:inAppMessageData encoding:NSUTF8StringEncoding];
[self unitySendMessageTo:self.unityInAppMessageGameObjectName withMethod:self.unityInAppMessageCallbackFunctionName withMessage:dataString];
if ([self.appboyUnityPlist[ABKUnityHandleInAppMessageDisplayKey] boolValue]) {
NSLog(@"Braze configured to display in-app messages despite presence of game object listener. Returning ABKDisplayInAppMessageNow.");
return ABKDisplayInAppMessageNow;
NSLog(@"Braze configured to display in-app messages despite presence of game object listener. Using display action: %ld.", (long)self.displayAction);
return self.displayAction;
}
return ABKDiscardInAppMessage;
}
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 3.4.0

##### Added
- Added the ability to change the display flow of In-App Messages directly from Unity code via `AppboyBinding.SetInAppMessageDisplayAction()`.
- See the `BrazeUnityInAppMessageDisplayActionType` enum.
- Added the ability to open the default Content Cards UI via `DisplayContentCards()` on the binding.
- For Android, this requires the following dependencies:
```
implementation "androidx.swiperefreshlayout:swiperefreshlayout:+"
implementation "androidx.recyclerview:recyclerview:+"
```

## 3.3.0

##### Breaking
Expand Down

0 comments on commit 337bf0c

Please sign in to comment.