Skip to content

Commit

Permalink
chore: init messaging push module
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Nov 21, 2024
1 parent 8bbb46d commit 80f0fd0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-sample-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ jobs:
- name: Setup workspace credentials in iOS environment files
run: |
cp "ios/Env.swift.example" "ios/Env.swift"
sd 'siteId: String = ".*"' "siteId: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_SITE_ID', matrix.sample-app)] }}\"" "ios/Env.swift"
sd 'apiKey: String = ".*"' "apiKey: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_API_KEY', matrix.sample-app)] }}\"" "ios/Env.swift"
sd 'cdpApiKey: String = ".*"' "cdpApiKey: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_CDP_API_KEY', matrix.sample-app)] }}\"" "ios/Env.swift"
# Make sure to fetch dependencies only after updating the version numbers and workspace credentials

Expand Down
3 changes: 1 addition & 2 deletions apps/amiapp_flutter/ios/Env.swift.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation

class Env {
static let siteId: String = "siteid"
static let apiKey: String = "apikey"
static let cdpApiKey: String = "cdpApiKey"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ class NotificationService: UNNotificationServiceExtension {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
print("NotificationService didReceive called")

// TODO: Fix SDK initialization
/*
CustomerIO.initialize(siteId: Env.siteId, apiKey: Env.apiKey, region: .US) { config in
config.autoTrackDeviceAttributes = true
config.logLevel = .debug
}
*/
MessagingPushFCM.initializeForExtension(
withConfig: MessagingPushConfigBuilder(cdpApiKey: Env.cdpApiKey)
.logLevel(.debug)
.build()
)

MessagingPush.shared.didReceive(request, withContentHandler: contentHandler)
}
Expand Down
8 changes: 4 additions & 4 deletions apps/amiapp_flutter/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import FirebaseCore

Messaging.messaging().delegate = self

// TODO: Fix MessagingPush initialization
/*
MessagingPushFCM.initialize(configOptions: nil)
*/
MessagingPushFCM.initialize(
withConfig: MessagingPushConfigBuilder()
.build()
)

// Sets a 3rd party push event handler for the app besides the Customer.io SDK and FlutterFire.
// Setting the AppDelegate to be the handler will internally use `flutter_local_notifications` to handle the push event.
Expand Down
6 changes: 5 additions & 1 deletion apps/amiapp_flutter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ void main() async {
// Setup flutter_local_notifications plugin to send local notifications and receive callbacks for them.
var initSettingsAndroid = const AndroidInitializationSettings("app_icon");
// The default settings will show local push notifications while app in foreground with plugin.
var initSettingsIOS = const DarwinInitializationSettings();
var initSettingsIOS = const DarwinInitializationSettings(
requestAlertPermission: false,
requestBadgePermission: false,
requestSoundPermission: false,
);
var initSettings = InitializationSettings(
android: initSettingsAndroid,
iOS: initSettingsIOS,
Expand Down
2 changes: 1 addition & 1 deletion apps/amiapp_flutter/lib/src/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class _SettingsScreenState extends State<SettingsScreen> {

@override
void initState() {
CustomerIO.instance.pushMessaging.getRegisteredDeviceToken().then((value) =>
CustomerIO.pushMessaging.getRegisteredDeviceToken().then((value) =>
setState(() => _deviceTokenValueController.text = value ?? ''));

final cioConfig = widget._customerIOSDK.sdkConfig;
Expand Down
10 changes: 9 additions & 1 deletion lib/customer_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ class CustomerIO {
}

/// Access push messaging functionality
CustomerIOMessagingPushPlatform get pushMessaging => _pushMessaging;
static CustomerIOMessagingPushPlatform get pushMessaging {
if (_instance == null) {
throw StateError(
'CustomerIO SDK must be initialized before accessing push module.\n'
'Call CustomerIO.initialize() first.',
);
}
return _instance!._pushMessaging;
}

/// Access in-app messaging functionality
CustomerIOMessagingInAppPlatform get inAppMessaging => _inAppMessaging;
Expand Down

0 comments on commit 80f0fd0

Please sign in to comment.