Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: initialize messaging push module #178

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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,
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated it to disable push permission on app launch

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we should be throwing here and crashing, probably just log maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same how we do for instance in feature branch. Since we need to return a non-null value, we unfortunately can't simply log and continue here.

'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
Loading