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

[Feedback]: Migration guide from 3.5.1 to 5.0.0 #711

Open
1 task done
Fudal opened this issue Aug 21, 2023 · 32 comments
Open
1 task done

[Feedback]: Migration guide from 3.5.1 to 5.0.0 #711

Fudal opened this issue Aug 21, 2023 · 32 comments

Comments

@Fudal
Copy link

Fudal commented Aug 21, 2023

What's on your mind?

We need migration guide from 3.5.1 to 5.0.0.

A lot of methods have been added or changed. The version jump itself testifies to this, but no migration guide has been presented to us, so users are confused.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@petodavid
Copy link

Here is the migration guide:

https://github.com/OneSignal/OneSignal-Flutter-SDK/blob/user_model/main/MIGRATION_GUIDE.md

@Fudal
Copy link
Author

Fudal commented Aug 22, 2023

@petodavid okay, thanks. But I can't see anywhere what should I replace these methods:

  1. OneSignal.shared.setExternalUserId(userId)
  2. OneSignal.shared.setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event)
  3. OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result)
  4. OneSignal.shared.promptUserForPushNotificationPermission()

@xunreal75
Copy link

Please update docs and example

target 'OneSignalNotificationServiceExtension' do
  use_frameworks!
  pod 'OneSignalXCFramework', '5.0.1'
end

is necessary for iOS to get Pod installed

@emawby
Copy link
Contributor

emawby commented Aug 22, 2023

Thank you for the feedback we will work on clarifying the migration steps!

@wahyu-handayani
Copy link

@petodavid okay, thanks. But I can't see anywhere what should I replace these methods:

  1. OneSignal.shared.setExternalUserId(userId)
  2. OneSignal.shared.setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event)
  3. OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result)
  4. OneSignal.shared.promptUserForPushNotificationPermission()

I have the same case like yours, did you find any solution ?

@Fudal
Copy link
Author

Fudal commented Sep 1, 2023

@wahyu-handayani no, I'm still using 3.5.1 version

@huszm
Copy link

huszm commented Sep 2, 2023

@Fudal @wahyu-handayani
The solution from me are
change OneSignal.shared.setNotificationOpenedHandler(_handleNotificationOpened) to OneSignal.Notifications.addClickListener(_handleNotificationOpened)

change _handleNotificationOpened(OSNotificationOpenedResult result) to _handleNotificationOpened(OSNotificationClickEvent result)

@xunreal75
Copy link

Hi this should help you to get started Onesignal V5.0.0

  if (kDebugMode) {
        OneSignal.Debug.setAlertLevel(OSLogLevel.none);
        OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
      } else {
        OneSignal.Debug.setAlertLevel(OSLogLevel.none);
        OneSignal.Debug.setLogLevel(OSLogLevel.none);
      }

      OneSignal.initialize(oneSignalAppId); //init with your appid
      OneSignal.Location.setShared(false); //avoid location sharing

      OneSignal.Notifications.addForegroundWillDisplayListener((event) {
      });

      OneSignal.Notifications.addPermissionObserver((state) {
         //log.i(text: 'Accepted Onesignal permission: $state');
      });

      OneSignal.InAppMessages.addWillDisplayListener((event) {
        //log.i(text: 'inAppMessage ${event.message}');
      });


      OneSignal.Notifications.addClickListener((event) {
        //var json = action.jsonRepresentation();
        var clickName = event.result.actionId;
        var clickURL = event.notification.launchUrl;
        var title = event.notification.title;
        var body = event.notification.body;
        ...
        }

@wahyu-handayani
Copy link

wahyu-handayani commented Sep 6, 2023

@wahyu-handayani no, I'm still using 3.5.1 version

I try to install onesignal using this version, may I take a look your Podfile and NotificationService.m (inside ios/OneSignalNotificationServiceExtension/ folder) ? because I always failed when debugging in ios

@Fudal
Copy link
Author

Fudal commented Sep 6, 2023

@wahyu-handayani

Sure, here is NotificationService.m:

//
//  NotificationService.m
//  OneSignalNotificationServiceExtension
//
//  Created by Brad Hesse on 7/13/18.
//  Copyright © 2018 The Chromium Authors. All rights reserved.
//

#import <OneSignal/OneSignal.h>

#import "NotificationService.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.receivedRequest = request;
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];
    
    [OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent withContentHandler:self.contentHandler];
}

- (void)serviceExtensionTimeWillExpire {
    // Called just before the extension will be terminated by the system.
    // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
    
    [OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
    
    self.contentHandler(self.bestAttemptContent);
}

@end

here Podfile:

# Uncomment this line to define a global platform for your project
platform :ios, '14.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|

   target.build_configurations.each do |config|
        # Here are some configurations automatically generated by flutter
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
          '$(inherited)',

          ## dart: PermissionGroup.calendar
          # 'PERMISSION_EVENTS=0',

          ## dart: PermissionGroup.reminders
          'PERMISSION_REMINDERS=0',

          ## dart: PermissionGroup.contacts
          # 'PERMISSION_CONTACTS=0',

          ## dart: PermissionGroup.camera
          'PERMISSION_CAMERA=1',

          'PERMISSION_ACTIVITY_RECOGNITION=1',

          ## dart: PermissionGroup.microphone
          # 'PERMISSION_MICROPHONE=1',

          ## dart: PermissionGroup.speech
          # 'PERMISSION_SPEECH_RECOGNIZER=0',

          ## dart: PermissionGroup.photos
          'PERMISSION_PHOTOS=0',

          ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
          # 'PERMISSION_LOCATION=0',

          ## dart: PermissionGroup.notification
          'PERMISSION_NOTIFICATIONS=1',

          ## dart: PermissionGroup.mediaLibrary
          'PERMISSION_MEDIA_LIBRARY=0',

          ## dart: PermissionGroup.sensors
          # 'PERMISSION_SENSORS=1',

          ## dart: PermissionGroup.bluetooth
          # 'PERMISSION_BLUETOOTH=0',
        ]
      end
    flutter_additional_ios_build_settings(target)
  end
end

@Fudal
Copy link
Author

Fudal commented Sep 6, 2023

@wahyu-handayani No problem ;)

I don't have that target
Zrzut ekranu 2023-09-6 o 09 20 55

@wahyu-handayani
Copy link

@wahyu-handayani No problem ;)

I don't have that target Zrzut ekranu 2023-09-6 o 09 20 55

Thank you so so sooooooooo much @Fudal for your help, I am still strugling to fix one error left, your helps really makes my day

@tovidd
Copy link

tovidd commented Sep 14, 2023

  1. Not sure about this OneSignal.shared.setExternalUserId
  2. OneSignal.shared.setNotificationWillShowInForegroundHandler to OneSignal.Notifications.addForegroundWillDisplayListener
  3. OneSignal.shared.setNotificationOpenedHandler to OneSignal.Notifications.addClickListener
  4. OneSignal.shared.promptUserForPushNotificationPermission to await OneSignal.Notifications.requestPermission(true)

I still have problem with android background notification, don't know why NotificationServiceExtension is error.

@husainazkas
Copy link

Please update migration guide as described on the comment reference. All of these methods are missing without any replacement instruction.

@petodavid okay, thanks. But I can't see anywhere what should I replace these methods:

  1. OneSignal.shared.setExternalUserId(userId)
  2. OneSignal.shared.setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event)
  3. OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result)
  4. OneSignal.shared.promptUserForPushNotificationPermission()

@michael-joseph-payne
Copy link

I have yet to get iOS to finish building using this guide or any of the pending PR changes to it.

@Fudal
Copy link
Author

Fudal commented Sep 25, 2023

@emawby We are still waiting for more information about right migration from 3.5.1 version.

@lukeurban
Copy link

Deprecation would be nice first. Throwing braking changes randomly to a product is a weak move NGL.

@elsegund0
Copy link

how can i fix this?

The getter 'shared' isn't defined for the type 'OneSignal'.
Undefined class 'OSNotificationOpenedResult'.
Undefined class 'OSNotificationReceivedEvent'.

@Fudal
Copy link
Author

Fudal commented Oct 25, 2023

@emawby or @nan-li can you help us?
I didn't find solution in example file.

@rignaneseleo
Copy link

How do I disable the foreground notifications in the new SDK?
In the old one, it was:

OneSignal.shared.setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event) {
  // Display Notification, send null to not display, send notification to display           
  event.complete(event.notification);      
}); 

In the new SDK event doesn't have the complete func.

@nandakista
Copy link

How do I disable the foreground notifications in the new SDK? In the old one, it was:

OneSignal.shared.setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event) {
  // Display Notification, send null to not display, send notification to display           
  event.complete(event.notification);      
}); 

In the new SDK event doesn't have the complete func.

Same problem here, there is event.preventDefault but its completely blocks push notification. I need the app still get notification but not showing in the foreground.
Is there any solution please ?

@hosaysg
Copy link

hosaysg commented Dec 11, 2023

How to retrieve tags?

@nan-li
Copy link
Contributor

nan-li commented Dec 11, 2023

Hi all,

I apologize we don't have a direct v3 -> v5 migration guide yet showing the appropriate replacements. All available methods of the major release are outline here.

@tovidd is correct about the methods and the replacement for setExternalUserId is the OneSignal.login("EXT_ID") method.

To address this comment

Deprecation would be nice first. Throwing braking changes randomly to a product is a weak move NGL.

The v3.x.x OneSignal Flutter SDK is still supported, but the major release of v5.x.x does introduce breaking changes if you upgrade.

@rignaneseleo you can call preventDefault to disable foreground notifications. Please see the guide for how to use.

@nandakista Can you tell me more about this issue you are running into?

@shanelau
Copy link

How to call event.complete(null) in version 5.0.4?
I need the app still get notification but not showing in the foreground.

@bugrevealingbme
Copy link

Login method is not working instead of setExternalUserId. I don't know what it does but nothing happens. Android/ios. This is important bug

@nan-li
Copy link
Contributor

nan-li commented Feb 1, 2024

Hi @shanelau I apologize for the delay, we have an example in the migration guide on the Notification Will Display Listener:

OneSignal.Notifications.addForegroundWillDisplayListener((event) {
	/// preventDefault to not display the notification
	event.preventDefault();

	/// Do async work

	/// notification.display() to display after preventing default
	event.notification.display();
});

@nan-li
Copy link
Contributor

nan-li commented Feb 1, 2024

Hi @bugrevealingbme,

Can you share more details about Login method is not working?

@bugrevealingbme
Copy link

Hi @bugrevealingbme,

Can you share more details about Login method is not working?

The problem was with me, I apologize for the misinformation. Externally, how do I check if a notification is clicked when the app is closed? There is not a document about it

@shanelau
Copy link

shanelau commented Feb 1, 2024

Hi @shanelau I apologize for the delay, we have an example in the migration guide on the Notification Will Display Listener:

OneSignal.Notifications.addForegroundWillDisplayListener((event) {
	/// preventDefault to not display the notification
	event.preventDefault();

	/// Do async work

	/// notification.display() to display after preventing default
	event.notification.display();
});

Nice work. It works on onesignal_flutter: ^5.1.0

@parvxi
Copy link

parvxi commented Feb 4, 2024

event.complete(null)

did u fine a solution?

@jhandaya
Copy link

jhandaya commented May 15, 2024

Where is postNotification method ?

final notification = OSCreateNotification(
    playerIds: listOneSignalUserId,
    androidSmallIcon: 'ic_stat_one_signal_default',
    androidLargeIcon: 'ic_stat_one_signal_default',
    content: message,
    androidSound: sound,
    heading: title,
    languageCode: 'en',
    iosAttachments: {
      "id1": imgUrlString
    },
    //url: url,
    //bigPicture: imgUrlString,
    buttons: [
      OSActionButton(text: "OK", id: "id1"),
    ]);

var response = await OneSignal.shared.postNotification(notification);

any solution to post a notification from version 5 ?

@michelemanniello
Copy link

same problem, any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests