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

[ECO-5119] Opt out default push handler #560

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
25 changes: 16 additions & 9 deletions example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
NSLog("application:didFailToRegisterForRemoteNotificationsWithError was called with error: %@", error.localizedDescription)
}

/// An example of how you handle push notification if you opt-out from using Ably Pushes by adding `AblyFlutterHandlePushNotifications` equal to `NO` in your project's Info.plist file:
///
/// (This method is deprecated, use the new one from `UNUserNotificationCenter` as recommented by Apple, it's here for the sake of simplest example)
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
NSLog("Notification received: \(userInfo)")
}
}
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AblyFlutterHandlePushNotifications</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
Expand Down
20 changes: 14 additions & 6 deletions ios/Classes/AblyFlutter.m
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,11 @@ +(void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {

// initializing method channel for round-trip method calls
FlutterMethodChannel *const methodChannel = [FlutterMethodChannel methodChannelWithName:@"io.ably.flutter.plugin" binaryMessenger:[registrar messenger] codec:methodCodec];
AblyFlutter *const ably = [[AblyFlutter alloc] initWithChannel:methodChannel streamsChannel: streamsChannel registrar:registrar];
NSNumber *handleAPNs = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AblyFlutterHandlePushNotifications"];
AblyFlutter *const ably = [[AblyFlutter alloc] initWithChannel:methodChannel
streamsChannel:streamsChannel
registrar:registrar
handleAPNs:handleAPNs != nil ? [handleAPNs boolValue] : NO];

// registering method channel with registrar
[registrar addMethodCallDelegate:ably channel:methodChannel];
Expand All @@ -708,18 +712,22 @@ +(void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {

-(instancetype)initWithChannel:(FlutterMethodChannel *const)channel
streamsChannel:(AblyStreamsChannel *const)streamsChannel
registrar:(NSObject<FlutterPluginRegistrar>*)registrar {
registrar:(NSObject<FlutterPluginRegistrar>*)registrar
handleAPNs:(BOOL)handleAPNs {
self = [super init];
if (!self) {
return nil;
}
_instanceStore = [AblyInstanceStore sharedInstance];
_channel = channel;
_streamsChannel = streamsChannel;
UNUserNotificationCenter *const center = UNUserNotificationCenter.currentNotificationCenter;
_pushNotificationEventHandlers = [[PushNotificationEventHandlers alloc] initWithDelegate: center.delegate andMethodChannel: channel];
center.delegate = _pushNotificationEventHandlers;


if (handleAPNs) {
UNUserNotificationCenter *const center = UNUserNotificationCenter.currentNotificationCenter;
_pushNotificationEventHandlers = [[PushNotificationEventHandlers alloc] initWithDelegate: center.delegate andMethodChannel: channel];
center.delegate = _pushNotificationEventHandlers;
}

_handlers = @{
AblyPlatformMethod_getPlatformVersion: _getPlatformVersion,
AblyPlatformMethod_getVersion: _getVersion,
Expand Down
Loading