Skip to content

Commit 93a509e

Browse files
committed
updates fixes and cleanup during iOS testing
1 parent 4f4fa65 commit 93a509e

13 files changed

+95
-72
lines changed

android/src/main/java/com/onesignal/flutter/OneSignalInAppMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class OneSignalInAppMessages extends FlutterRegistrarResponder implements
2424

2525
static void registerWith(BinaryMessenger messenger) {
2626
OneSignalInAppMessages sharedInstance = new OneSignalInAppMessages();
27+
2728
sharedInstance.messenger = messenger;
2829
sharedInstance.channel = new MethodChannel(messenger, "OneSignal#inappmessages");
2930
sharedInstance.channel.setMethodCallHandler(sharedInstance);

android/src/main/java/com/onesignal/flutter/OneSignalNotifications.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class OneSignalNotifications extends FlutterRegistrarResponder implements
4141
private boolean hasSetNotificationWillShowInForegroundHandler = false;
4242
private final HashMap<String, INotificationReceivedEvent> notificationReceivedEventCache = new HashMap<>();
4343

44-
4544
static void registerWith(BinaryMessenger messenger) {
4645
OneSignalNotifications controller = new OneSignalNotifications();
4746
controller.messenger = messenger;
@@ -123,6 +122,12 @@ private void completeNotification(MethodCall call, Result result) {
123122
} else {
124123
notificationReceivedEvent.complete(null);
125124
}
125+
126+
synchronized (notificationReceivedEvent) {
127+
notificationReceivedEventCache.remove(notificationId);
128+
notificationReceivedEvent.notify();
129+
}
130+
126131
replySuccess(result, null);
127132
}
128133

@@ -161,6 +166,16 @@ public void notificationWillShowInForeground(INotificationReceivedEvent notifica
161166
try {
162167
HashMap<String, Object> receivedMap = OneSignalSerializer.convertNotificationToMap(notification);
163168
invokeMethodOnUiThread("OneSignal#handleNotificationWillShowInForeground", receivedMap);
169+
try {
170+
171+
synchronized (notificationReceivedEvent) {
172+
while(notificationReceivedEventCache.containsKey(notification.getNotificationId()))
173+
notificationReceivedEvent.wait();
174+
}
175+
} catch(InterruptedException e){
176+
Logging.error("InterruptedException" + e.toString(), null);
177+
}
178+
164179
} catch (JSONException e) {
165180
e.getStackTrace();
166181
Logging.error("Encountered an error attempting to convert INotification object to hash map:" + e.toString(), null);
@@ -172,7 +187,7 @@ public void onPermissionChanged(boolean permission) {
172187
invokeMethodOnUiThread("OneSignal#OSPermissionChanged", OneSignalSerializer.convertPermissionChanged(permission));
173188
}
174189

175-
public void lifecycleInit() {
190+
private void lifecycleInit() {
176191
OneSignal.getNotifications().setNotificationWillShowInForegroundHandler(this);
177192
OneSignal.getNotifications().addPermissionChangedHandler(this);
178193
}

android/src/main/java/com/onesignal/flutter/OneSignalPushSubscription.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private void optOut(MethodCall call, Result reply) {
5959
replySuccess(reply, null);
6060
}
6161

62-
public void lifecycleInit() {
62+
private void lifecycleInit() {
6363
OneSignal.getUser().getPushSubscription().addChangeHandler(this);
6464
}
6565

example/ios/Flutter/Flutter.podspec

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# NOTE: This podspec is NOT to be published. It is only used as a local source!
3+
# This is a generated file; do not edit or check into version control.
4+
#
5+
6+
Pod::Spec.new do |s|
7+
s.name = 'Flutter'
8+
s.version = '1.0.0'
9+
s.summary = 'A UI toolkit for beautiful and fast apps.'
10+
s.homepage = 'https://flutter.dev'
11+
s.license = { :type => 'BSD' }
12+
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
13+
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
14+
s.ios.deployment_target = '11.0'
15+
# Framework linking is handled by Flutter tooling, not CocoaPods.
16+
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
17+
s.vendored_frameworks = 'path/to/nothing'
18+
end

example/ios/Podfile.lock

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
PODS:
22
- Flutter (1.0.0)
3-
- onesignal_flutter (5.0.0-beta-01):
3+
- onesignal_flutter (5.0.0-beta-02):
44
- Flutter
5-
- OneSignalXCFramework (= 5.0.0-beta-01)
6-
- OneSignalXCFramework (5.0.0-beta-01):
7-
- OneSignalXCFramework/OneSignalCore (= 5.0.0-beta-01)
8-
- OneSignalXCFramework/OneSignalExtension (= 5.0.0-beta-01)
9-
- OneSignalXCFramework/OneSignalNotifications (= 5.0.0-beta-01)
10-
- OneSignalXCFramework/OneSignalOSCore (= 5.0.0-beta-01)
11-
- OneSignalXCFramework/OneSignalOutcomes (= 5.0.0-beta-01)
12-
- OneSignalXCFramework/OneSignalUser (= 5.0.0-beta-01)
13-
- OneSignalXCFramework/OneSignalCore (5.0.0-beta-01)
14-
- OneSignalXCFramework/OneSignalExtension (5.0.0-beta-01):
5+
- OneSignalXCFramework (= 5.0.0-beta-02)
6+
- OneSignalXCFramework (5.0.0-beta-02):
7+
- OneSignalXCFramework/OneSignalCore (= 5.0.0-beta-02)
8+
- OneSignalXCFramework/OneSignalExtension (= 5.0.0-beta-02)
9+
- OneSignalXCFramework/OneSignalNotifications (= 5.0.0-beta-02)
10+
- OneSignalXCFramework/OneSignalOSCore (= 5.0.0-beta-02)
11+
- OneSignalXCFramework/OneSignalOutcomes (= 5.0.0-beta-02)
12+
- OneSignalXCFramework/OneSignalUser (= 5.0.0-beta-02)
13+
- OneSignalXCFramework/OneSignalCore (5.0.0-beta-02)
14+
- OneSignalXCFramework/OneSignalExtension (5.0.0-beta-02):
1515
- OneSignalXCFramework/OneSignalCore
1616
- OneSignalXCFramework/OneSignalOutcomes
17-
- OneSignalXCFramework/OneSignalNotifications (5.0.0-beta-01):
17+
- OneSignalXCFramework/OneSignalNotifications (5.0.0-beta-02):
1818
- OneSignalXCFramework/OneSignalCore
1919
- OneSignalXCFramework/OneSignalExtension
2020
- OneSignalXCFramework/OneSignalOutcomes
21-
- OneSignalXCFramework/OneSignalOSCore (5.0.0-beta-01):
21+
- OneSignalXCFramework/OneSignalOSCore (5.0.0-beta-02):
2222
- OneSignalXCFramework/OneSignalCore
23-
- OneSignalXCFramework/OneSignalOutcomes (5.0.0-beta-01):
23+
- OneSignalXCFramework/OneSignalOutcomes (5.0.0-beta-02):
2424
- OneSignalXCFramework/OneSignalCore
25-
- OneSignalXCFramework/OneSignalUser (5.0.0-beta-01):
25+
- OneSignalXCFramework/OneSignalUser (5.0.0-beta-02):
2626
- OneSignalXCFramework/OneSignalCore
2727
- OneSignalXCFramework/OneSignalNotifications
2828
- OneSignalXCFramework/OneSignalOSCore
@@ -31,7 +31,7 @@ PODS:
3131
DEPENDENCIES:
3232
- Flutter (from `Flutter`)
3333
- onesignal_flutter (from `.symlinks/plugins/onesignal_flutter/ios`)
34-
- OneSignalXCFramework (= 5.0.0-beta-01)
34+
- OneSignalXCFramework (= 5.0.0-beta-02)
3535

3636
SPEC REPOS:
3737
trunk:
@@ -45,9 +45,9 @@ EXTERNAL SOURCES:
4545

4646
SPEC CHECKSUMS:
4747
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
48-
onesignal_flutter: e369a8100290b3680412e27e91255916dd23ca22
49-
OneSignalXCFramework: 7d3eb90c3e78908b0d72aa88600bfdab694460ec
48+
onesignal_flutter: bd487de9496226e9d1c3fb1cdd0828eb89823896
49+
OneSignalXCFramework: c5d8671065c95db06567730c29dd739f887def45
5050

51-
PODFILE CHECKSUM: 004b8b86fe167483a0c84378eebc1addff2ac31b
51+
PODFILE CHECKSUM: 33df664a2d5067e5102be29dbfecdaaa4da1b8a9
5252

5353
COCOAPODS: 1.11.3

example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class _MyAppState extends State<MyApp>
6363
OneSignal.Notifications.setNotificationWillShowInForegroundHandler(
6464
(OSNotificationReceivedEvent event) {
6565
print(
66-
'FOREGROUND HANDLER CALLED WITH1: ${event.notification.jsonRepresentation()}');
66+
'FOREGROUND HANDLER CALLED WITH: ${event.notification.jsonRepresentation()}');
6767

6868
/// Display Notification, send null to not display
6969
event.complete(null);
@@ -231,7 +231,7 @@ class _MyAppState extends State<MyApp>
231231
OneSignal.InAppMessages.removeTriggers(keys);
232232

233233
// Toggle pausing (displaying or not) of IAMs
234-
OneSignal.InAppMessages.paused(true);
234+
OneSignal.InAppMessages.paused(false);
235235
var arePaused = await OneSignal.InAppMessages.arePaused();
236236
print('Notifications paused ${arePaused}');
237237
}

ios/Classes/OSFlutterInAppMessages.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
4848
binaryMessenger:[registrar messenger]];
4949

5050
[registrar addMethodCallDelegate:OSFlutterInAppMessages.sharedInstance channel:OSFlutterInAppMessages.sharedInstance.channel];
51-
52-
[OneSignal.InAppMessages setClickHandler:^(OSInAppMessageAction *action) {
53-
[OSFlutterInAppMessages.sharedInstance handleInAppMessageClicked:action];
54-
}];
55-
[OneSignal.InAppMessages setLifecycleHandler:OSFlutterInAppMessages.sharedInstance];
5651
}
5752

5853
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
@@ -72,6 +67,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
7267
result(@([OneSignal.InAppMessages paused]));
7368
else if ([@"OneSignal#initInAppMessageClickedHandlerParams" isEqualToString:call.method])
7469
[self initInAppMessageClickedHandlerParams];
70+
else if ([@"OneSignal#lifecycleInit" isEqualToString:call.method])
71+
[self lifecycleInit:call withResult:result];
7572
else
7673
result(FlutterMethodNotImplemented);
7774

@@ -106,6 +103,14 @@ - (void)paused:(FlutterMethodCall *)call withResult:(FlutterResult)result {
106103
result(nil);
107104
}
108105

106+
- (void)lifecycleInit:(FlutterMethodCall *)call withResult:(FlutterResult)result {
107+
[OneSignal.InAppMessages setClickHandler:^(OSInAppMessageAction *action) {
108+
[OSFlutterInAppMessages.sharedInstance handleInAppMessageClicked:action];
109+
}];
110+
[OneSignal.InAppMessages setLifecycleHandler:OSFlutterInAppMessages.sharedInstance];
111+
}
112+
113+
109114

110115
#pragma mark In App Message Click
111116
- (void)initInAppMessageClickedHandlerParams {

ios/Classes/OSFlutterNotifications.m

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
5151
binaryMessenger:[registrar messenger]];
5252

5353
[registrar addMethodCallDelegate:OSFlutterNotifications.sharedInstance channel:OSFlutterNotifications.sharedInstance.channel];
54-
55-
[OneSignal.Notifications setNotificationWillShowInForegroundHandler:^(OSNotification *notification, OSNotificationDisplayResponse completion) {
56-
[OSFlutterNotifications.sharedInstance handleNotificationWillShowInForeground:notification completion:completion];
57-
}];
5854
}
5955

6056
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
@@ -68,16 +64,14 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
6864
[self requestPermission:call withResult:result];
6965
else if ([@"OneSignal#registerForProvisionalAuthorization" isEqualToString:call.method])
7066
[self registerForProvisionalAuthorization:call withResult:result];
71-
else if ([@"OneSignal#addPermissionObserver" isEqualToString:call.method])
72-
[self addPermissionObserver:call withResult:result];
73-
else if ([@"OneSignal#removePermissionObserver" isEqualToString:call.method])
74-
[self removePermissionObserver:call withResult:result];
7567
else if ([@"OneSignal#initNotificationWillShowInForegroundHandlerParams" isEqualToString:call.method])
7668
[self initNotificationWillShowInForegroundHandlerParams];
7769
else if ([@"OneSignal#completeNotification" isEqualToString:call.method])
7870
[self completeNotification:call withResult:result];
7971
else if ([@"OneSignal#initNotificationOpenedHandlerParams" isEqualToString:call.method])
80-
[self initNotificationOpenedHandlerParams];
72+
[self initNotificationOpenedHandlerParams:call withResult:result];
73+
else if ([@"OneSignal#lifecycleInit" isEqualToString:call.method])
74+
[self lifecycleInit:call withResult:result];
8175
else
8276
result(FlutterMethodNotImplemented);
8377
}
@@ -88,6 +82,7 @@ - (void)clearAll:(FlutterMethodCall *)call withResult:(FlutterResult)result {
8882
}
8983

9084
- (void)requestPermission:(FlutterMethodCall *)call withResult:(FlutterResult)result {
85+
NSLog(@"henryhenryhenryrequestPermission");
9186
BOOL fallbackToSettings = [call.arguments[@"fallbackToSettings"] boolValue];
9287

9388
[OneSignal.Notifications requestPermission:^(BOOL accepted) {
@@ -101,15 +96,20 @@ - (void)registerForProvisionalAuthorization:(FlutterMethodCall *)call withResult
10196
}];
10297
}
10398

104-
- (void)onOSPermissionChanged:(OSPermissionState*)state {
105-
[self.channel invokeMethod:@"OneSignal#OSPermissionChanged" arguments:state.jsonRepresentation];
106-
}
107-
108-
- (void)addPermissionObserver:(FlutterMethodCall *)call withResult:(FlutterResult)result {
99+
- (void)lifecycleInit:(FlutterMethodCall *)call withResult:(FlutterResult)result {
100+
[OneSignal.Notifications setNotificationWillShowInForegroundHandler:^(OSNotification *notification, OSNotificationDisplayResponse completion) {
101+
[OSFlutterNotifications.sharedInstance handleNotificationWillShowInForeground:notification completion:completion];
102+
}];
109103
[OneSignal.Notifications addPermissionObserver:self];
110104
result(nil);
111105
}
112106

107+
108+
109+
- (void)onOSPermissionChanged:(OSPermissionState*)state {
110+
[self.channel invokeMethod:@"OneSignal#OSPermissionChanged" arguments:state.jsonRepresentation];
111+
}
112+
113113
#pragma mark Received in Foreground Notification
114114

115115
- (void)initNotificationWillShowInForegroundHandlerParams {
@@ -150,10 +150,11 @@ - (void)completeNotification:(FlutterMethodCall *)call withResult:(FlutterResult
150150

151151
#pragma mark Opened Notification
152152

153-
- (void)initNotificationOpenedHandlerParams {
153+
- (void)initNotificationOpenedHandlerParams:(FlutterMethodCall *)call withResult:(FlutterResult)result {
154154
[OneSignal.Notifications setNotificationOpenedHandler:^(OSNotificationOpenedResult * _Nonnull result) {
155155
[OSFlutterNotifications.sharedInstance handleNotificationOpened:result];
156156
}];
157+
result(nil);
157158
}
158159

159160
- (void)handleNotificationOpened:(OSNotificationOpenedResult *)result {

ios/Classes/OSFlutterPushSubscription.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
@interface OSFlutterPushSubscription : NSObject<FlutterPlugin, OSPushSubscriptionObserver>
3434

35+
+ (instancetype)sharedInstance;
3536
@property (strong, nonatomic) FlutterMethodChannel *channel;
3637

3738
@end

ios/Classes/OSFlutterPushSubscription.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
5353
[self optIn:call withResult:result];
5454
else if ([@"OneSignal#optOut" isEqualToString:call.method])
5555
[self optOut:call withResult:result];
56-
else if ([@"OneSignal#lifecycleInit" isEqualToString:call.method])
57-
[self removeObserver:call withResult:result];
56+
else if ([@"OneSignal#lifecycleInit" isEqualToString:call.method])
57+
[self lifecycleInit:call withResult:result];
5858
else
5959
result(FlutterMethodNotImplemented);
6060
}
@@ -75,7 +75,7 @@ - (void)lifecycleInit:(FlutterMethodCall *)call withResult:(FlutterResult)result
7575
}
7676

7777
- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges*)stateChanges {
78-
[self.channel invokeMethod:@"OneSignal#pushSubscriptionChanged" arguments:stateChanges.jsonRepresentation];
78+
[self.channel invokeMethod:@"OneSignal#pushSubscriptionChanged" arguments:stateChanges.to.jsonRepresentation];
7979
}
8080

8181
@end

0 commit comments

Comments
 (0)