Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import <UIKit/UIKit.h>
#import <OneSignalFramework/OneSignalFramework.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener, OSUserStateObserver, OSUserJwtInvalidatedListener>
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener, OSUserStateObserver, OSUserJwtInvalidatedListener, OSLogListener>

@property (strong, nonatomic) UIWindow *window;

Expand Down
6 changes: 6 additions & 0 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// [FIRApp configure];

NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]);
// Uncomment to test LogListener
// [OneSignal.Debug addLogListener:self];
[OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE];
[OneSignal.Debug setAlertLevel:ONE_S_LL_NONE];

Expand Down Expand Up @@ -203,4 +205,8 @@ - (void)application:(UIApplication *)application
completionHandler(UIBackgroundFetchResultNoData);
}

- (void)onLogEvent:(OneSignalLogEvent * _Nonnull)event {
NSLog(@"Dev App onLogEvent: %@", event.entry);
}

@end
8 changes: 7 additions & 1 deletion iOS_SDK/OneSignalDevApp/OneSignalDevApp/SwiftTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
import Foundation
import OneSignalFramework

class SwiftTest: NSObject, OSUserJwtInvalidatedListener {
class SwiftTest: NSObject, OSUserJwtInvalidatedListener, OSLogListener {
func onLogEvent(_ event: OneSignalLogEvent) {
print("Dev App onLogEvent: \(event.level) - \(event.entry)")
}

func onUserJwtInvalidated(event: OSUserJwtInvalidatedEvent) {
print("event: \(event.jsonRepresentation())")
print("externalId: \(event.externalId)")
Expand All @@ -42,5 +46,7 @@ class SwiftTest: NSObject, OSUserJwtInvalidatedListener {
OneSignal.updateUserJwt(externalId: "euid", token: "token")
OneSignal.addUserJwtInvalidatedListener(self)
OneSignal.removeUserJwtInvalidatedListener(self)
OneSignal.Debug.addLogListener(self)
OneSignal.Debug.removeLogListener(self)
}
}
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2678,9 +2678,9 @@
4529DF0B1FA932AC00CEAB1D /* OneSignalTrackFirebaseAnalytics.m */,
DE7D1831270279D9002D3A5D /* OSNotificationClasses.h */,
DE7D183527027AA0002D3A5D /* OneSignalLog.h */,
DE7D183327027A73002D3A5D /* OneSignalLog.m */,
3CCF44BC299B17290021964D /* OneSignalWrapper.h */,
3CCF44BD299B17290021964D /* OneSignalWrapper.m */,
DE7D183327027A73002D3A5D /* OneSignalLog.m */,
DE7D187627037A16002D3A5D /* OneSignalCoreHelper.h */,
DE7D187827037A26002D3A5D /* OneSignalCoreHelper.m */,
7AE28B8725B8ADF400529100 /* OSMacros.h */,
Expand Down
31 changes: 31 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,41 @@ typedef NS_ENUM(NSUInteger, ONE_S_LOG_LEVEL) {
ONE_S_LL_VERBOSE
};

@interface OneSignalLogEvent : NSObject
@property(readonly)ONE_S_LOG_LEVEL level;
@property(readonly, nonnull)NSString *entry;
@end

@protocol OSLogListener <NSObject>
- (void)onLogEvent:(OneSignalLogEvent *_Nonnull)event;
@end

@protocol OSDebug <NSObject>
/**
The log level the OneSignal SDK should be writing to the Xcode log. Defaults to [LogLevel.WARN].

WARNING: This should not be set higher than LogLevel.WARN in a production setting.
*/
+ (void)setLogLevel:(ONE_S_LOG_LEVEL)logLevel;
/**
The log level the OneSignal SDK should be showing as a modal. Defaults to [LogLevel.NONE].

WARNING: This should not be used in a production setting.
*/
+ (void)setAlertLevel:(ONE_S_LOG_LEVEL)logLevel NS_REFINED_FOR_SWIFT;
+ (void)_dump;
/**
Add a listener to receive all logging messages the SDK produces.
Useful to capture and send logs to your server.

NOTE: All log messages are always passed, LogLevel has no effect on this.
*/
+ (void)addLogListener:(NSObject<OSLogListener>*_Nonnull)listener NS_REFINED_FOR_SWIFT;
/**
Removes a listener added by addLogListener
*/
+ (void)removeLogListener:(NSObject<OSLogListener>*_Nonnull)listener NS_REFINED_FOR_SWIFT;

@end

@interface OneSignalLog : NSObject <OSDebug>
Expand Down
38 changes: 38 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
#import "OneSignalLog.h"
#import "OSDialogInstanceManager.h"

@implementation OneSignalLogEvent
- (instancetype)initWithLevel:(ONE_S_LOG_LEVEL)level entry:(NSString*)entry {
_level = level;
_entry = entry;
return self;
}
@end

/**
Implements the Log Level methods of protocol `OSDebug`.
The `_dump` method will be implemented in OneSignal module.
Expand All @@ -42,6 +50,15 @@ @implementation OneSignalLog
return self;
}

+ (NSMutableArray<NSObject<OSLogListener> *>*)logListeners {
Comment thread
nan-li marked this conversation as resolved.
Outdated
static NSMutableArray<NSObject<OSLogListener> *> *_logListeners;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_logListeners = [NSMutableArray new];
});
return _logListeners;
}

+ (void)setLogLevel:(ONE_S_LOG_LEVEL)nsLogLevel {
_nsLogLevel = nsLogLevel;
}
Expand All @@ -50,6 +67,18 @@ + (void)setAlertLevel:(ONE_S_LOG_LEVEL)logLevel {
_alertLogLevel = logLevel;
}

+ (void)addLogListener:(NSObject<OSLogListener>*_Nonnull)listener {
@synchronized(self.logListeners) {
[self.logListeners addObject:listener];
}
}

+ (void)removeLogListener:(NSObject<OSLogListener>*_Nonnull)listener {
@synchronized(self.logListeners) {
[self.logListeners removeObject:listener];
}
}

+ (void)_dump {}

+ (void)onesignalLog:(ONE_S_LOG_LEVEL)logLevel message:(NSString* _Nonnull)message {
Expand Down Expand Up @@ -92,6 +121,15 @@ void onesignal_Log(ONE_S_LOG_LEVEL logLevel, NSString* message) {
if (logLevel <= _alertLogLevel) {
[[OSDialogInstanceManager sharedInstance] presentDialogWithTitle:levelString withMessage:message withActions:nil cancelTitle:NSLocalizedString(@"Close", @"Close button") withActionCompletion:nil];
}

@synchronized(OneSignalLog.logListeners) {
for (NSObject<OSLogListener> *listener in OneSignalLog.logListeners) {
Comment thread
nan-li marked this conversation as resolved.
Outdated
if ([listener respondsToSelector:@selector(onLogEvent:)]) {
OneSignalLogEvent *event = [[OneSignalLogEvent alloc] initWithLevel:logLevel entry:[levelString stringByAppendingString:message]];
[listener onLogEvent:event];
}
}
}
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ public class MockUserRequests: NSObject {
]
}

public static func testUnauthorizedailureError() -> NSError {
public static func testUnauthorizedailureError() -> OneSignalClientError {
let userInfo = ["returned": [
"errors": [["title": "token has invalid claims: token is expired", "code": "auth-0"]],
"httpStatusCode": 401
]]
return NSError(domain: "not-important", code: 401, userInfo: userInfo)
let nsError = NSError(domain: "not-important", code: 401, userInfo: userInfo)
let error = OneSignalClientError(code: 401, message: "not-important", responseHeaders: nil, response: nil, underlyingError: nsError)
return error!
}
}

Expand Down
20 changes: 20 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,29 @@ public extension OneSignal {
}

public extension OSDebug {
/**
The log level the OneSignal SDK should be showing as a modal. Defaults to [LogLevel.NONE].

WARNING: This should not be used in a production setting.
*/
static func setAlertLevel(_ logLevel: ONE_S_LOG_LEVEL) {
__setAlert(logLevel)
}
/**
Add a listener to receive all logging messages the SDK produces.
Useful to capture and send logs to your server.

NOTE: All log messages are always passed, LogLevel has no effect on this.
*/
static func addLogListener(_ listener: OSLogListener) {
__add(listener)
}
/**
Removes a listener added by addLogListener
*/
static func removeLogListener(_ listener: OSLogListener) {
__remove(listener)
}
}

public extension OSInAppMessages {
Expand Down
Loading