Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

foobar #1537

Closed
wants to merge 11 commits into from
395 changes: 375 additions & 20 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,13 @@ NS_ASSUME_NONNULL_BEGIN

+ (OSMessagingController *)sharedInstance;
+ (void)start;
+ (void)removeInstance;
- (void)presentInAppMessage:(OSInAppMessageInternal *)message;
- (void)getInAppMessagesFromServer:(NSString * _Nullable)subscriptionId;
- (void)messageViewImpressionRequest:(OSInAppMessageInternal *)message;
- (void)messageViewPageImpressionRequest:(OSInAppMessageInternal *)message withPageId:(NSString *)pageId;

- (BOOL)isInAppMessagingPaused;
- (void)setInAppMessagingPaused:(BOOL)pause;
- (void)addTriggers:(NSDictionary<NSString *, id> *)triggers;
- (void)removeTriggersForKeys:(NSArray<NSString *> *)keys;
- (void)clearTriggers;
- (NSDictionary<NSString *, id> *)getTriggers;
- (id)getTriggerValueForKey:(NSString *)key;

- (void)addInAppMessageClickListener:(NSObject<OSInAppMessageClickListener> *_Nullable)listener;
- (void)removeInAppMessageClickListener:(NSObject<OSInAppMessageClickListener> *_Nullable)listener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*/

#import "OSMessagingController.h"
#import "UIApplication+OneSignal.h" // Previously imported via "OneSignalHelper.h"
#import "NSDateFormatter+OneSignal.h" // Previously imported via "OneSignalHelper.h"
#import "UIApplication+OneSignal.h"
#import "NSDateFormatter+OneSignal.h"
#import <OneSignalCore/OneSignalCore.h>
#import "OSInAppMessageClickResult.h"
#import "OSInAppMessageClickEvent.h"
Expand Down Expand Up @@ -165,6 +165,7 @@ + (OSMessagingController *)sharedInstance {
return sharedInstance;
}

// TODO: Used by tests only? Come back and see if this is needed.
+ (void)removeInstance {
sharedInstance = nil;
once = 0;
Expand Down Expand Up @@ -815,10 +816,6 @@ - (void)clearTriggers {
return self.triggerController.getTriggers;
}

- (id)getTriggerValueForKey:(NSString *)key {
return [self.triggerController getTriggerValueForKey:key];
}

#pragma mark OSInAppMessageViewControllerDelegate Methods
- (void)messageViewControllerDidDisplay:(OSInAppMessageInternal *)message {
[self onDidDisplayInAppMessage:message];
Expand Down Expand Up @@ -1227,7 +1224,6 @@ - (void)addTriggers:(NSDictionary<NSString *, id> *)triggers {}
- (void)removeTriggersForKeys:(NSArray<NSString *> *)keys {}
- (void)clearTriggers {}
- (NSDictionary<NSString *, id> *)getTriggers { return @{}; }
- (id)getTriggerValueForKey:(NSString *)key { return 0; }
#pragma mark OSInAppMessageViewControllerDelegate Methods
- (void)messageViewControllerWasDismissed {}
- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageClickResult *)action {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)addTriggers:(NSDictionary<NSString *, id> *)triggers;
- (void)removeTriggersForKeys:(NSArray<NSString *> *)keys;
- (NSDictionary<NSString *, id> *)getTriggers;
- (id)getTriggerValueForKey:(NSString *)key;
- (void)timeSinceLastMessage:(NSDate *)date;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ - (void)removeTriggersForKeys:(NSArray<NSString *> *)keys {
}
}

- (id)getTriggerValueForKey:(NSString *)key {
@synchronized (self.triggers) {
return self.triggers[key];
}
}

/*
* Part of redisplay logic
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ of this software and associated documentation files (the "Software"), to deal
#import "OSInAppMessagingRequests.h"

@implementation OSRequestGetInAppMessages
- (NSString *)description {
return [NSString stringWithFormat:@"<OSRequestGetInAppMessages from %@>", self.path];
}

+ (instancetype _Nonnull) withSubscriptionId:(NSString * _Nonnull)subscriptionId
withSessionDuration:(NSNumber * _Nonnull)sessionDuration
withRetryCount:(NSNumber *)retryCount
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
disabled_rules:
- identifier_name
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Modified MIT License

Copyright 2024 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
@testable import OneSignalInAppMessages

let OS_TEST_MESSAGE_ID = "a4b3gj7f-d8cc-11e4-bed1-df8f05be55ba"
let OS_TEST_MESSAGE_VARIANT_ID = "m8dh7234f-d8cc-11e4-bed1-df8f05be55ba"
let OS_TEST_ENGLISH_VARIANT_ID = "11e4-bed1-df8f05be55ba-m8dh7234f-d8cc"

let OS_DUMMY_HTML = "<html><h1>Hello World</h1></html>"

@objc
public class IAMTestHelpers: NSObject {
/// Convert OSTriggerOperatorType enum to string
private static func OS_OPERATOR_TO_STRING(_ type: Int32) -> String {
// Trigger operator strings
let OS_OPERATOR_STRINGS: [String] = [
"greater",
"less",
"equal",
"not_equal",
"less_or_equal",
"greater_or_equal",
"exists",
"not_exists",
"in"
]

return OS_OPERATOR_STRINGS[Int(type)]
}

@objc
public static func testDefaultMessageJson() -> [String: Any] {
return [
"id": String(format: "%@_%i", OS_TEST_MESSAGE_ID, UUID().uuidString),
"variants": [
"ios": [
"default": OS_TEST_MESSAGE_VARIANT_ID,
"en": OS_TEST_ENGLISH_VARIANT_ID
],
"all": [
"default": "should_never_be_used_by_any_test"
]
],
"triggers": []
]
}

@objc
public static func testMessageJsonWithTrigger(property: String, triggerId: String, type: Int32, value: Any) -> [String: Any] {
var testMessage = self.testDefaultMessageJson()

testMessage["triggers"] = [
[
[
"kind": property,
"property": property,
"operator": OS_OPERATOR_TO_STRING(type),
"value": value,
"id": triggerId
]
]
]
return testMessage
}

@objc
public static func testFetchMessagesResponse(messages: [[String: Any]]) -> [String: Any] {
return [
"in_app_messages": messages
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Modified MIT License

Copyright 2025 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 <OneSignalCore/OneSignalCore.h>

NS_ASSUME_NONNULL_BEGIN

@interface MockMessagingController : NSObject
+ (NSArray <OSInAppMessage *> *)messageDisplayQueue; // TODO: may need to be changed to return OSInAppMessageInternal
+ (BOOL)isInAppMessageShowing;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Modified MIT License

Copyright 2025 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 "MockMessagingController.h"
#import "OSMessagingController.h"

@interface OSMessagingController ()
@property (strong, nonatomic, nonnull) NSMutableArray <OSInAppMessageInternal *> *messageDisplayQueue;
@end

@implementation MockMessagingController
+ (void)resetState {
// TODO: reseting OSMessagingController state between tests
}

+ (NSArray *)messageDisplayQueue {
return OSMessagingController.sharedInstance.messageDisplayQueue;
}

+ (BOOL)isInAppMessageShowing {
return OSMessagingController.sharedInstance.isInAppMessageShowing;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Modified MIT License

Copyright 2025 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>

//! Project version number for OneSignalInAppMessagesMocks.
FOUNDATION_EXPORT double OneSignalInAppMessagesMocksVersionNumber;

//! Project version string for OneSignalInAppMessagesMocks.
FOUNDATION_EXPORT const unsigned char OneSignalInAppMessagesMocksVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <OneSignalInAppMessagesMocks/PublicHeader.h>

#import <OneSignalInAppMessagesMocks/MockMessagingController.h>
Loading
Loading