Skip to content

Commit e166e63

Browse files
authored
Merge pull request #640 from OneSignal/user_model/debug_namespace
Adding Debug namespace
2 parents 0227035 + 782bc5b commit e166e63

File tree

9 files changed

+166
-61
lines changed

9 files changed

+166
-61
lines changed

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
6BBCCF44B691DF76AC7D7376 /* Pods-Runner.debug.xcconfig */,
180180
47FF2D2152AD7B79C3388A8D /* Pods-Runner.release.xcconfig */,
181181
);
182-
name = Pods;
183182
path = Pods;
184183
sourceTree = "<group>";
185184
};
@@ -596,10 +595,7 @@
596595
"$(PROJECT_DIR)/Flutter",
597596
);
598597
INFOPLIST_FILE = Runner/Info.plist;
599-
LD_RUNPATH_SEARCH_PATHS = (
600-
"$(inherited)",
601-
"@executable_path/Frameworks",
602-
);
598+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
603599
LIBRARY_SEARCH_PATHS = (
604600
"$(inherited)",
605601
"$(PROJECT_DIR)/Flutter",
@@ -625,10 +621,7 @@
625621
"$(PROJECT_DIR)/Flutter",
626622
);
627623
INFOPLIST_FILE = Runner/Info.plist;
628-
LD_RUNPATH_SEARCH_PATHS = (
629-
"$(inherited)",
630-
"@executable_path/Frameworks",
631-
);
624+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
632625
LIBRARY_SEARCH_PATHS = (
633626
"$(inherited)",
634627
"$(PROJECT_DIR)/Flutter",
@@ -657,12 +650,8 @@
657650
ENABLE_BITCODE = NO;
658651
GCC_C_LANGUAGE_STANDARD = gnu11;
659652
INFOPLIST_FILE = OneSignalNotificationServiceExtension/Info.plist;
660-
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
661-
LD_RUNPATH_SEARCH_PATHS = (
662-
"$(inherited)",
663-
"@executable_path/Frameworks",
664-
"@executable_path/../../Frameworks",
665-
);
653+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
654+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
666655
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;
667656
PRODUCT_NAME = "$(TARGET_NAME)";
668657
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -690,12 +679,8 @@
690679
ENABLE_BITCODE = NO;
691680
GCC_C_LANGUAGE_STANDARD = gnu11;
692681
INFOPLIST_FILE = OneSignalNotificationServiceExtension/Info.plist;
693-
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
694-
LD_RUNPATH_SEARCH_PATHS = (
695-
"$(inherited)",
696-
"@executable_path/Frameworks",
697-
"@executable_path/../../Frameworks",
698-
);
682+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
683+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
699684
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;
700685
PRODUCT_NAME = "$(TARGET_NAME)";
701686
PROVISIONING_PROFILE_SPECIFIER = "";

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
31-
<Testables>
32-
</Testables>
3330
<MacroExpansion>
3431
<BuildableReference
3532
BuildableIdentifier = "primary"
@@ -39,14 +36,13 @@
3936
ReferencedContainer = "container:Runner.xcodeproj">
4037
</BuildableReference>
4138
</MacroExpansion>
42-
<AdditionalOptions>
43-
</AdditionalOptions>
39+
<Testables>
40+
</Testables>
4441
</TestAction>
4542
<LaunchAction
4643
buildConfiguration = "Debug"
4744
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4845
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49-
language = ""
5046
launchStyle = "0"
5147
useCustomWorkingDirectory = "NO"
5248
ignoresPersistentStateOnLaunch = "NO"
@@ -63,8 +59,6 @@
6359
ReferencedContainer = "container:Runner.xcodeproj">
6460
</BuildableReference>
6561
</BuildableProductRunnable>
66-
<AdditionalOptions>
67-
</AdditionalOptions>
6862
</LaunchAction>
6963
<ProfileAction
7064
buildConfiguration = "Release"

example/lib/main.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ class _MyAppState extends State<MyApp> {
3232
Future<void> initPlatformState() async {
3333
if (!mounted) return;
3434

35-
// OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);
35+
OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
36+
37+
OneSignal.Debug.setVisualLevel(OSLogLevel.verbose);
38+
39+
// NOTE: Replace with your own app ID from https://www.onesignal.com
40+
OneSignal.shared.initialize("9c59a2aa-315a-4bf9-9fef-f76d575d3202");
3641

3742
// OneSignal.shared.setRequiresUserPrivacyConsent(_requireConsent);
3843

@@ -100,10 +105,6 @@ class _MyAppState extends State<MyApp> {
100105
// print("ON DID DISMISS IN APP MESSAGE ${message.messageId}");
101106
// });
102107

103-
// NOTE: Replace with your own app ID from https://www.onesignal.com
104-
await OneSignal.shared
105-
.setAppId("380dc082-5231-4cc2-ab51-a03da5a0e4c2");
106-
107108
// iOS-only method to open launch URLs in Safari when set to false
108109
// OneSignal.shared.setLaunchURLsInApp(false);
109110

ios/Classes/OSFlutterDebug.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2017 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
29+
#import <Foundation/Foundation.h>
30+
#import <Flutter/Flutter.h>
31+
32+
@interface OSFlutterDebug : NSObject<FlutterPlugin>
33+
34+
@property (strong, nonatomic) FlutterMethodChannel *channel;
35+
36+
@end

ios/Classes/OSFlutterDebug.m

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2023 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import "OSFlutterDebug.h"
29+
#import <OneSignalFramework/OneSignalFramework.h>
30+
#import "OSFlutterCategories.h"
31+
32+
@implementation OSFlutterDebug
33+
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
34+
OSFlutterDebug *instance = [OSFlutterDebug new];
35+
36+
instance.channel = [FlutterMethodChannel
37+
methodChannelWithName:@"OneSignal#debug"
38+
binaryMessenger:[registrar messenger]];
39+
40+
[registrar addMethodCallDelegate:instance channel:instance.channel];
41+
}
42+
43+
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
44+
if ([@"OneSignal#setLogLevel" isEqualToString:call.method])
45+
[self setLogLevel:call];
46+
else if ([@"OneSignal#setVisualLevel" isEqualToString:call.method])
47+
[self setVisualLevel:call];
48+
else
49+
result(FlutterMethodNotImplemented);
50+
}
51+
52+
- (void)setLogLevel:(FlutterMethodCall *)call {
53+
[OneSignal.Debug setLogLevel:call.arguments[@"logLevel"]];
54+
}
55+
56+
- (void)setVisualLevel:(FlutterMethodCall *)call {
57+
[OneSignal.Debug setVisualLevel:call.arguments[@"visualLevel"]];
58+
}
59+
60+
@end

ios/Classes/OneSignalPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#import <Flutter/Flutter.h>
2929
#import <OneSignalFramework/OneSignalFramework.h>
3030

31-
@interface OneSignalPlugin : NSObject<FlutterPlugin, OSPermissionObserver>
31+
@interface OneSignalPlugin : NSObject<FlutterPlugin>
3232

3333
// Do NOT initialize instances of this class.
3434
// You must only reference the shared instance.

ios/Classes/OneSignalPlugin.m

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#import "OneSignalPlugin.h"
2929
#import "OSFlutterCategories.h"
30+
#import "OSFlutterDebug.h"
31+
3032

3133
@interface OneSignalPlugin ()
3234

@@ -58,29 +60,24 @@ + (instancetype)sharedInstance {
5860
#pragma mark FlutterPlugin
5961
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
6062

61-
[OneSignal initialize:nil withLaunchOptions:nil];
6263
[OneSignal setMSDKType:@"flutter"];
6364

64-
// Wrapper SDK's call init with no app ID early on in the
65-
// app lifecycle. The developer will call init() later on
66-
// from the Flutter plugin channel.
67-
6865
OneSignalPlugin.sharedInstance.channel = [FlutterMethodChannel
6966
methodChannelWithName:@"OneSignal"
7067
binaryMessenger:[registrar messenger]];
7168

7269
[registrar addMethodCallDelegate:OneSignalPlugin.sharedInstance channel:OneSignalPlugin.sharedInstance.channel];
73-
70+
[OSFlutterDebug registerWithRegistrar:registrar];
7471
}
7572

7673
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
7774
if ([@"OneSignal#initialize" isEqualToString:call.method])
78-
[self initialize:call withResult:result];
75+
[self initialize:call];
7976
else
8077
result(FlutterMethodNotImplemented);
8178
}
8279

83-
- (void)initialize:(FlutterMethodCall *)call withResult:(FlutterResult)result {
80+
- (void)initialize:(FlutterMethodCall *)call {
8481

8582
[OneSignal initialize:call.arguments[@"appId"] withLaunchOptions:nil];
8683
// If the user has required privacy consent, the SDK will not
@@ -91,8 +88,7 @@ - (void)initialize:(FlutterMethodCall *)call withResult:(FlutterResult)result {
9188
// } else {
9289
// [self addObservers];
9390
// }
94-
result(nil);
91+
// result(nil);
9592
}
9693

97-
9894
@end

lib/onesignal_flutter.dart

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import 'package:flutter/services.dart';
44
import 'package:onesignal_flutter/src/permission.dart';
55
import 'package:onesignal_flutter/src/defines.dart';
66
import 'package:onesignal_flutter/src/utils.dart';
7+
import 'package:onesignal_flutter/src/onesignaldebug.dart';
78

89
export 'src/permission.dart';
910
export 'src/defines.dart';
11+
export 'src/onesignaldebug.dart';
1012

1113

1214
// Handlers for various events
@@ -19,30 +21,24 @@ class OneSignal {
1921
/// so if you create multiple instances of OneSignal, they will
2022
/// mostly share the same state.
2123
static OneSignal shared = new OneSignal();
24+
static OneSignalDebug Debug = new OneSignalDebug();
2225

2326

2427
// private channels used to bridge to ObjC/Java
2528
MethodChannel _channel = const MethodChannel('OneSignal');
26-
// MethodChannel _tagsChannel = const MethodChannel('OneSignal#tags');
27-
28-
// event handlers
29-
PermissionChangeHandler? _onPermissionChangedHandler;
30-
29+
30+
/// The initializer for OneSignal.
31+
///
32+
/// The initializer accepts an [appId] which the developer can get
33+
/// from the OneSignal consoleas well as a dictonary of [launchOptions]
34+
void initialize(String appId) {
35+
_channel.invokeMethod(
36+
'OneSignal#initialize', {'appId': appId});
37+
}
3138
// constructor method
3239
OneSignal() {
3340
this._channel.setMethodCallHandler(_handleMethod);
3441
}
35-
36-
/// The initializer for OneSignal. Note that this initializer
37-
/// accepts an iOSSettings object, in Android you can pass null.
38-
Future<void> setAppId(String appId) async {
39-
// _onesignalLog(OSLogLevel.verbose,
40-
// "Initializing the OneSignal Flutter SDK ($sdkVersion)");
41-
42-
await _channel.invokeMethod(
43-
'OneSignal#initialize', {'appId': appId});
44-
}
45-
4642
// Private function that gets called by ObjC/Java
4743
Future<Null> _handleMethod(MethodCall call) async {
4844
return null;

lib/src/onesignaldebug.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'dart:async';
2+
import 'dart:io' show Platform;
3+
import 'package:flutter/services.dart';
4+
import 'package:onesignal_flutter/src/defines.dart';
5+
6+
class OneSignalDebug {
7+
8+
// private channels used to bridge to ObjC/Java
9+
MethodChannel _channel = const MethodChannel('OneSignal#debug');
10+
11+
// constructor method
12+
OneSignalDebug() {
13+
this._channel.setMethodCallHandler(_handleMethod);
14+
}
15+
// Private function that gets called by ObjC/Java
16+
Future<Null> _handleMethod(MethodCall call) async {
17+
return null;
18+
}
19+
20+
/// Sets the log level for the SDK.
21+
///
22+
/// The parameter [logLevel] controls
23+
/// how verbose logs in the console/logcat are
24+
void setLogLevel(OSLogLevel logLevel) {
25+
_channel.invokeMethod("OneSignal#setLogLevel",
26+
{'console': logLevel.index});
27+
}
28+
29+
/// Sets the log level for the SDK.
30+
///
31+
/// The parameter [visualLevel] controls
32+
/// if the SDK will show alerts for each logged message
33+
void setVisualLevel( OSLogLevel visualLevel) {
34+
_channel.invokeMethod("OneSignal#setVisualLevel",
35+
{'visual': visualLevel.index});
36+
}
37+
}

0 commit comments

Comments
 (0)