Skip to content

Commit 1735f64

Browse files
committed
Move live activities to its own namespace
1 parent 088db41 commit 1735f64

File tree

5 files changed

+137
-45
lines changed

5 files changed

+137
-45
lines changed

ios/Classes/OSFlutterLiveActivities.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 <Foundation/Foundation.h>
29+
#import <Flutter/Flutter.h>
30+
31+
@interface OSFlutterLiveActivities : NSObject<FlutterPlugin>
32+
33+
@property (strong, nonatomic) FlutterMethodChannel *channel;
34+
35+
@end

ios/Classes/OSFlutterLiveActivities.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 "OSFlutterLiveActivities.h"
29+
#import <OneSignalFramework/OneSignalFramework.h>
30+
#import "OSFlutterCategories.h"
31+
32+
@implementation OSFlutterLiveActivities
33+
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
34+
OSFlutterLiveActivities *instance = [OSFlutterLiveActivities new];
35+
36+
instance.channel = [FlutterMethodChannel
37+
methodChannelWithName:@"OneSignal#liveactivities"
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#enterLiveActivity" isEqualToString:call.method])
45+
[self enterLiveActivity:call withResult:result];
46+
else if ([@"OneSignal#exitLiveActivity" isEqualToString:call.method])
47+
[self exitLiveActivity:call withResult:result];
48+
else
49+
result(FlutterMethodNotImplemented);
50+
}
51+
52+
- (void)enterLiveActivity:(FlutterMethodCall *)call withResult:(FlutterResult)result {
53+
NSString *activityId = call.arguments[@"activityId"];
54+
NSString *token = call.arguments[@"token"];
55+
56+
[OneSignal enterLiveActivity:activityId withToken:token withSuccess:^(NSDictionary *results) {
57+
result(results);
58+
} withFailure:^(NSError *error) {
59+
result(error.flutterError);
60+
}];
61+
}
62+
63+
- (void)exitLiveActivity:(FlutterMethodCall *)call withResult:(FlutterResult)result {
64+
NSString *activityId = call.arguments[@"activityId"];
65+
66+
[OneSignal exitLiveActivity:activityId withSuccess:^(NSDictionary *results) {
67+
result(results);
68+
} withFailure:^(NSError *error) {
69+
result(error.flutterError);
70+
}];
71+
}
72+
73+
@end

ios/Classes/OneSignalPlugin.m

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
8585
[self setConsentGiven:call withResult:result];
8686
else if ([@"OneSignal#setLaunchURLsInApp" isEqualToString:call.method])
8787
[self setLaunchURLsInApp:call withResult:result];
88-
else if ([@"OneSignal#enterLiveActivity" isEqualToString:call.method])
89-
[self enterLiveActivity:call withResult:result];
90-
else if ([@"OneSignal#exitLiveActivity" isEqualToString:call.method])
91-
[self exitLiveActivity:call withResult:result];
9288
else
9389
result(FlutterMethodNotImplemented);
9490
}
@@ -134,27 +130,4 @@ - (void)setLaunchURLsInApp:(FlutterMethodCall *)call withResult:(FlutterResult)r
134130
result(nil);
135131
}
136132

137-
#pragma mark Live Activity
138-
139-
- (void)enterLiveActivity:(FlutterMethodCall *)call withResult:(FlutterResult)result {
140-
NSString *activityId = call.arguments[@"activityId"];
141-
NSString *token = call.arguments[@"token"];
142-
143-
[OneSignal enterLiveActivity:activityId withToken:token withSuccess:^(NSDictionary *results) {
144-
result(results);
145-
} withFailure:^(NSError *error) {
146-
result(error.flutterError);
147-
}];
148-
}
149-
150-
- (void)exitLiveActivity:(FlutterMethodCall *)call withResult:(FlutterResult)result {
151-
NSString *activityId = call.arguments[@"activityId"];
152-
153-
[OneSignal exitLiveActivity:activityId withSuccess:^(NSDictionary *results) {
154-
result(results);
155-
} withFailure:^(NSError *error) {
156-
result(error.flutterError);
157-
}];
158-
}
159-
160133
@end

lib/onesignal_flutter.dart

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import 'package:onesignal_flutter/src/notifications.dart';
77
import 'package:onesignal_flutter/src/session.dart';
88
import 'package:onesignal_flutter/src/location.dart';
99
import 'package:onesignal_flutter/src/inappmessages.dart';
10+
import 'package:onesignal_flutter/src/liveactivities.dart';
1011

1112
export 'src/defines.dart';
1213
export 'src/pushsubscription.dart';
1314
export 'src/subscription.dart';
1415
export 'src/notification.dart';
1516
export 'src/notifications.dart';
1617
export 'src/inappmessage.dart';
18+
export 'src/liveactivities.dart';
1719

1820
class OneSignal {
1921
/// A singleton representing the OneSignal SDK.
@@ -27,6 +29,7 @@ class OneSignal {
2729
static OneSignalSession Session = new OneSignalSession();
2830
static OneSignalLocation Location = new OneSignalLocation();
2931
static OneSignalInAppMessages InAppMessages = new OneSignalInAppMessages();
32+
static OneSignalLiveActivities LiveActivities = new OneSignalLiveActivities();
3033

3134
// private channels used to bridge to ObjC/Java
3235
MethodChannel _channel = const MethodChannel('OneSignal');
@@ -98,22 +101,4 @@ class OneSignal {
98101
'OneSignal#setLaunchURLsInApp', {'launchUrlsInApp': launchUrlsInApp});
99102
}
100103
}
101-
102-
/// Only applies to iOS
103-
/// Associates a temporary push token with an Activity ID on the OneSignal server.
104-
Future<void> enterLiveActivity(String activityId, String token) async {
105-
if (Platform.isIOS) {
106-
return await _channel.invokeMethod("OneSignal#enterLiveActivity",
107-
{'activityId': activityId, 'token': token});
108-
}
109-
}
110-
111-
/// Only applies to iOS
112-
/// Deletes activityId associated temporary push token on the OneSignal server.
113-
Future<void> exitLiveActivity(String activityId) async {
114-
if (Platform.isIOS) {
115-
return await _channel.invokeMethod(
116-
"OneSignal#exitLiveActivity", {'activityId': activityId});
117-
}
118-
}
119104
}

lib/src/liveactivities.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'dart:async';
2+
import 'dart:io';
3+
import 'package:flutter/services.dart';
4+
5+
class OneSignalLiveActivities {
6+
// private channels used to bridge to ObjC/Java
7+
MethodChannel _channel = const MethodChannel('OneSignal#liveactivities');
8+
9+
/// Only applies to iOS
10+
/// Associates a temporary push token with an Activity ID on the OneSignal server.
11+
Future<void> enterLiveActivity(String activityId, String token) async {
12+
if (Platform.isIOS) {
13+
return await _channel.invokeMethod("OneSignal#enterLiveActivity",
14+
{'activityId': activityId, 'token': token});
15+
}
16+
}
17+
18+
/// Only applies to iOS
19+
/// Deletes activityId associated temporary push token on the OneSignal server.
20+
Future<void> exitLiveActivity(String activityId) async {
21+
if (Platform.isIOS) {
22+
return await _channel.invokeMethod(
23+
"OneSignal#exitLiveActivity", {'activityId': activityId});
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)