Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
7A9173A2231971E5007848FA /* OneSignalReceiveReceiptsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A9173A1231971E5007848FA /* OneSignalReceiveReceiptsController.m */; };
7AA2848A2406FC6400C25D76 /* OSInAppMessageTag.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1F2D8E2406EFC5007799A9 /* OSInAppMessageTag.m */; };
7AA2848B2406FC6500C25D76 /* OSInAppMessageTag.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1F2D8E2406EFC5007799A9 /* OSInAppMessageTag.m */; };
7AD172382416D53B00A78B19 /* OSInAppMessageLocationPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AD172372416D53B00A78B19 /* OSInAppMessageLocationPrompt.m */; };
7AD172392416D53B00A78B19 /* OSInAppMessageLocationPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AD172372416D53B00A78B19 /* OSInAppMessageLocationPrompt.m */; };
7AD1723A2416D53B00A78B19 /* OSInAppMessageLocationPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AD172372416D53B00A78B19 /* OSInAppMessageLocationPrompt.m */; };
7AD8DDE7234BD3BE00747A8A /* OneSignalUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AD8DDE6234BD3BE00747A8A /* OneSignalUserDefaults.m */; };
7ADE379422E8B69C00263048 /* OneSignalOutcomeEventsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7ADE379322E8B69C00263048 /* OneSignalOutcomeEventsController.m */; };
7ADE37AD22F2554400263048 /* OneSignalOutcomeEventsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7ADE379322E8B69C00263048 /* OneSignalOutcomeEventsController.m */; };
Expand Down Expand Up @@ -422,6 +425,8 @@
7A880F302404AE7B0081F5E8 /* OSInAppMessagePushPrompt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessagePushPrompt.m; sourceTree = "<group>"; };
7A9173A1231971E5007848FA /* OneSignalReceiveReceiptsController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalReceiveReceiptsController.m; sourceTree = "<group>"; };
7A9173A3231971F8007848FA /* OneSignalReceiveReceiptsController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalReceiveReceiptsController.h; sourceTree = "<group>"; };
7AD172362416D52D00A78B19 /* OSInAppMessageLocationPrompt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageLocationPrompt.h; sourceTree = "<group>"; };
7AD172372416D53B00A78B19 /* OSInAppMessageLocationPrompt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageLocationPrompt.m; sourceTree = "<group>"; };
7AD8DDE6234BD3BE00747A8A /* OneSignalUserDefaults.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalUserDefaults.m; sourceTree = "<group>"; };
7AD8DDE8234BD3CF00747A8A /* OneSignalUserDefaults.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalUserDefaults.h; sourceTree = "<group>"; };
7ADE379322E8B69C00263048 /* OneSignalOutcomeEventsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OneSignalOutcomeEventsController.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -967,6 +972,8 @@
7A880F2E2404AD010081F5E8 /* OSInAppMessagePrompt.h */,
7A880F2F2404AD920081F5E8 /* OSInAppMessagePushPrompt.h */,
7A880F302404AE7B0081F5E8 /* OSInAppMessagePushPrompt.m */,
7AD172362416D52D00A78B19 /* OSInAppMessageLocationPrompt.h */,
7AD172372416D53B00A78B19 /* OSInAppMessageLocationPrompt.m */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -1237,6 +1244,7 @@
files = (
9D1BD968237A28FC00A064F7 /* OSUniqueOutcomeNotification.m in Sources */,
7A9173A2231971E5007848FA /* OneSignalReceiveReceiptsController.m in Sources */,
7AD172382416D53B00A78B19 /* OSInAppMessageLocationPrompt.m in Sources */,
9124120E1E73342200E41FD7 /* OneSignal.m in Sources */,
CACBAA97218A6243000ACAA5 /* OSMessagingController.m in Sources */,
CA36F35921C33A2500300C77 /* OSInAppMessageController.m in Sources */,
Expand Down Expand Up @@ -1310,6 +1318,7 @@
files = (
9D1BD969237A28FC00A064F7 /* OSUniqueOutcomeNotification.m in Sources */,
9124120F1E73342200E41FD7 /* OneSignal.m in Sources */,
7AD172392416D53B00A78B19 /* OSInAppMessageLocationPrompt.m in Sources */,
CACBAA98218A6243000ACAA5 /* OSMessagingController.m in Sources */,
CA36F35A21C33A2500300C77 /* OSInAppMessageController.m in Sources */,
CA08FC741FE99AFF004C445F /* OneSignalClient.m in Sources */,
Expand Down Expand Up @@ -1452,6 +1461,7 @@
CACBAAAA218A65AE000ACAA5 /* InAppMessagingTests.m in Sources */,
4529DEE71FA82CDC00CEAB1D /* UNUserNotificationCenterOverrider.m in Sources */,
4529DEDB1FA8284E00CEAB1D /* NSDataOverrider.m in Sources */,
7AD1723A2416D53B00A78B19 /* OSInAppMessageLocationPrompt.m in Sources */,
CA7FC8A221927229002C4FD9 /* OSDynamicTriggerController.m in Sources */,
9D3300F623145AF3000F0A83 /* OneSignalViewHelper.m in Sources */,
4529DEF31FA8440A00CEAB1D /* UIAlertViewOverrider.m in Sources */,
Expand Down
6 changes: 4 additions & 2 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#import "OSInAppMessageAction.h"
#import "OSInAppMessagePushPrompt.h"
#import "OSInAppMessageLocationPrompt.h"

@implementation OSInAppMessageAction

Expand Down Expand Up @@ -96,6 +97,8 @@ + (instancetype)instanceWithJson:(NSDictionary *)json {
for (NSString *prompt in promptActionsStrings) {
if ([prompt isEqualToString:@"push"]) {
[promptActions addObject:[[OSInAppMessagePushPrompt alloc] init]];
} else if ([prompt isEqualToString:@"location"]) {
[promptActions addObject:[[OSInAppMessageLocationPrompt alloc] init]];
}
}

Expand All @@ -105,8 +108,7 @@ + (instancetype)instanceWithJson:(NSDictionary *)json {
return action;
}

- (NSString *)description
{
- (NSString *)description {
return [NSString stringWithFormat:@"OSInAppMessageAction outcome: %@ \ntag: %@ promptAction: %@", _outcomes, _tags, [_promptActions description]];
}

Expand Down
39 changes: 39 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageLocationPrompt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Modified MIT License
*
* Copyright 2020 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef OSInAppMessageLocationPrompt_h
#define OSInAppMessageLocationPrompt_h

#import "OSInAppMessagePrompt.h"

@interface OSInAppMessageLocationPrompt : NSObject <OSInAppMessagePrompt>

@property (nonatomic) BOOL hasPrompted;

@end

#endif /* OSInAppMessageLocationPrompt_h */
56 changes: 56 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageLocationPrompt.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Modified MIT License
*
* Copyright 2020 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#import <Foundation/Foundation.h>
#import "OSInAppMessageLocationPrompt.h"

@interface OneSignal ()

+ (void)promptLocation:(void (^)(BOOL accepted))completionHandler;

@end

@implementation OSInAppMessageLocationPrompt

- (instancetype)init
{
self = [super init];
if (self) {
_hasPrompted = NO;
}
return self;
}

- (void)handlePrompt:(void (^)(BOOL accepted))completionHandler {
[OneSignal promptLocation:completionHandler];
}

- (NSString *)description {
return [NSString stringWithFormat:@"OSInAppMessageLocationPrompt hasPrompted:%@", _hasPrompted ? @"YES" : @"NO"];
}

@end
4 changes: 4 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ + (instancetype _Nullable)instancePreviewFromPayload:(OSNotificationPayload * _N
return nil;
}

- (NSString *)description {
return [NSString stringWithFormat:@"OSInAppMessageOutcome name: %@\nweight: %@unique: %s\n", _name, _weight, _unique ? "YES" : "NO"];
}

@end
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/Source/OSInAppMessagePrompt.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

@protocol OSInAppMessagePrompt <NSObject>

@property (nonatomic) BOOL didAppear;
@property (nonatomic) BOOL hasPrompted;

- (void)handlePrompt:(void (^)(BOOL accepted))completionHandler;

Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/Source/OSInAppMessagePushPrompt.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@interface OSInAppMessagePushPrompt : NSObject <OSInAppMessagePrompt>

@property (nonatomic) BOOL didAppear;
@property (nonatomic) BOOL hasPrompted;

@end

Expand Down
7 changes: 3 additions & 4 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessagePushPrompt.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ - (instancetype)init
{
self = [super init];
if (self) {
_didAppear = NO;
_hasPrompted = NO;
}
return self;
}
Expand All @@ -43,9 +43,8 @@ - (void)handlePrompt:(void (^)(BOOL accepted))completionHandler {
[OneSignal promptForPushNotificationsWithUserResponse:completionHandler fallbackToSettings:YES];
}

- (NSString *)description
{
return [NSString stringWithFormat:@"OSInAppMessagePushPrompt didappear:%@", _didAppear ? @"YES" : @"NO"];
- (NSString *)description {
return [NSString stringWithFormat:@"OSInAppMessagePushPrompt hasPrompted:%@", _hasPrompted ? @"YES" : @"NO"];
}

@end
8 changes: 7 additions & 1 deletion iOS_SDK/OneSignalSDK/Source/OSMessagingController.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@

NS_ASSUME_NONNULL_BEGIN

@interface OSMessagingController : NSObject <OSInAppMessageViewControllerDelegate, OSTriggerControllerDelegate>
@protocol OSMessagingControllerDelegate <NSObject>

- (void)onApplicationDidBecomeActive;

@end

@interface OSMessagingController : NSObject <OSInAppMessageViewControllerDelegate, OSTriggerControllerDelegate, OSMessagingControllerDelegate>

@property (class, readonly) BOOL isInAppMessagingPaused;

Expand Down
46 changes: 32 additions & 14 deletions iOS_SDK/OneSignalSDK/Source/OSMessagingController.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ @interface OSMessagingController ()

@property (nonatomic, nullable) NSObject<OSInAppMessagePrompt>*currentPromptAction;

@property (nonatomic) BOOL isAppInactive;

@end

@implementation OSMessagingController
Expand Down Expand Up @@ -136,6 +138,7 @@ - (instancetype)init {
self.clickedClickIds = [[NSMutableSet alloc] initWithSet:[standardUserDefaults getSavedSetForKey:OS_IAM_CLICKED_SET_KEY defaultValue:nil]];
self.impressionedInAppMessages = [[NSMutableSet alloc] initWithSet:[standardUserDefaults getSavedSetForKey:OS_IAM_IMPRESSIONED_SET_KEY defaultValue:nil]];
self.currentPromptAction = nil;
self.isAppInactive = NO;
// BOOL that controls if in-app messaging is paused or not (false by default)
[self setInAppMessagingPaused:false];
}
Expand Down Expand Up @@ -200,7 +203,12 @@ - (void)presentInAppMessage:(OSInAppMessage *)message {
// Return early if an IAM is already showing
if (self.isInAppMessageShowing)
return;

// Return early if the app is not active
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Pause IAMs display due to app inactivity"];
_isAppInactive = YES;
return;
}
[self displayMessage:message];
};
}
Expand Down Expand Up @@ -340,7 +348,6 @@ - (void)setDataForRedisplay:(OSInAppMessage *)message {
[self.impressionedInAppMessages removeObject:message.messageId];
[message clearClickIds];
return;

}
}
}
Expand Down Expand Up @@ -424,7 +431,9 @@ - (void)messageViewControllerWasDismissed {

if (!_currentPromptAction) {
[self evaluateMessageDisplayQueue];
} // else do nothing prompt is handling the re-showing
} else { //do nothing prompt is handling the re-showing
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Stop evaluateMessageDisplayQueue because prompt is currently displayed"];
}
}
}

Expand Down Expand Up @@ -473,26 +482,25 @@ - (void)persistInAppMessageForRedisplay:(OSInAppMessage *)message {
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"persistInAppMessageForRedisplay: %@ \nredisplayedInAppMessages: %@", [message description], [_redisplayedInAppMessages description]]];
}

- (void)handlePromptAction:(NSArray<NSObject<OSInAppMessagePrompt> *> *)promptActions {
- (void)handlePromptActions:(NSArray<NSObject<OSInAppMessagePrompt> *> *)promptActions {
for (NSObject<OSInAppMessagePrompt> *promptAction in promptActions) {
if (![promptAction didAppear]) {
// Don't show prompt twice
if (!promptAction.hasPrompted) {
_currentPromptAction = promptAction;
break;
}
break;
}

if (_currentPromptAction) {
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"IAM prompt to handle: %@", [_currentPromptAction description]]];
_currentPromptAction.didAppear = YES;
_currentPromptAction.hasPrompted = YES;
[_currentPromptAction handlePrompt:^(BOOL accepted) {
_currentPromptAction = nil;
// IAM dismissed by action
if (!_viewController) {
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"IAM with prompt dismissed from actionTaken"];
[self evaluateMessageDisplayQueue];
}
//TODO: continue handling more than one prompt
[self handlePromptActions:promptActions];
}];
} else if (!_viewController) { // IAM dismissed by action
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"IAM with prompt dismissed from actionTaken"];
[self evaluateMessageDisplayQueue];
}
}

Expand All @@ -503,7 +511,7 @@ - (void)messageViewDidSelectAction:(OSInAppMessage *)message withAction:(OSInApp
if (action.clickUrl)
[self handleMessageActionWithURL:action];

[self handlePromptAction:action.promptActions];
[self handlePromptActions:action.promptActions];

if (self.actionClickBlock)
self.actionClickBlock(action);
Expand Down Expand Up @@ -609,6 +617,16 @@ - (void)triggerConditionChanged {
[self evaluateMessages];
}

#pragma mark OSMessagingControllerDelegate Methods
- (void)onApplicationDidBecomeActive {
// To avoid excesive message evaluation
// we should re-evaluate all in-app messages only if it was paused by inactive
if (_isAppInactive) {
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Evaluating messages due to inactive app"];
_isAppInactive = NO;
[self evaluateMessages];
}
}
@end

@implementation DummyOSMessagingController
Expand Down
10 changes: 7 additions & 3 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions
_outcomeEventsController = [[OneSignalOutcomeEventsController alloc] init:self.sessionManager];

if (appId && mShareLocation)
[OneSignalLocation getLocation:false];
[OneSignalLocation getLocation:false withCompletionHandler:nil];

/*
* No need to call the handleNotificationOpened:userInfo as it will be called from one of the following selectors
Expand Down Expand Up @@ -1393,12 +1393,16 @@ + (void)setLocationShared:(BOOL)enable {
}
}

+ (void) promptLocation {
+ (void)promptLocation {
[self promptLocation:nil];
}

+ (void)promptLocation:(void (^)(BOOL accepted))completionHandler {
// return if the user has not granted privacy permissions
if ([self shouldLogMissingPrivacyConsentErrorWithMethodName:@"promptLocation"])
return;

[OneSignalLocation getLocation:true];
[OneSignalLocation getLocation:true withCompletionHandler:completionHandler];
}

+ (BOOL)isLocationShared {
Expand Down
6 changes: 3 additions & 3 deletions iOS_SDK/OneSignalSDK/Source/OneSignalLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ typedef struct os_last_location {
+ (bool)started;
+ (void)internalGetLocation:(bool)prompt;
- (void)locationManager:(id)manager didUpdateLocations:(NSArray *)locations;
+ (void) getLocation:(bool)prompt;
+ (void) sendLocation;
+ (void)getLocation:(bool)prompt withCompletionHandler:(void (^)(BOOL accepted))completionHandler;
+ (void)sendLocation;
+ (os_last_location*)lastLocation;
+ (void)clearLastLocation;
+ (void)onfocus:(BOOL)isActive;
+ (void)onFocus:(BOOL)isActive;

@end

Expand Down
Loading