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

FR: Support iOS 16 Simulator on Firebase Messaging #9968

Closed
ispiropoulos opened this issue Jun 30, 2022 · 4 comments · Fixed by #10503
Closed

FR: Support iOS 16 Simulator on Firebase Messaging #9968

ispiropoulos opened this issue Jun 30, 2022 · 4 comments · Fixed by #10503
Assignees
Labels
api: messaging type: feature request Xcode 14 - iOS 16 Issues and PRs related to Xcode 14, iOS 16, and associated OSes

Comments

@ispiropoulos
Copy link

Feature proposal

  • Firebase Component: Messaging

Trying to test remote notifications via Firebase Messaging on an Apple Silicon Mac with macOS Ventura and Xcode 14.
Getting this log message:

2022-06-30 15:56:00.487199+0300 my-project[75680:3976914] 9.2.0 - [FirebaseMessaging][I-FCM023014] Running InstanceID on a simulator doesn't have APNS. Use prod profile by default.

And notification sending fails with this error:
"errorCode": "UNREGISTERED"

The proposed change is to support iOS 16 simulators.

@paulb777
Copy link
Member

Thanks for the feature request. From the Xcode 14 Release notes:

Simulator now supports remote notifications in iOS 16 when running in macOS 13 on Mac computers with Apple silicon or T2 processors. Simulator supports the Apple Push Notification Service Sandbox environment. Your server can send a remote notification to your app running in that simulator by connecting to the APNS Sandbox (api.sandbox.push.apple.com). Each simulator generates registration tokens unique to the combination of that simulator and the Mac hardware it’s running on. See User Notifications for more information.

Remote Notifications support more features (like Notification Service Extensions) than locally simulated notifications using .apns payload files or the simctl push command.

Device Registration Tokens are of variable length. Tokens in Simulator may be larger than current physical device tokens. Don’t hardcode any specific length or format for these tokens. (60974170)

@KoCMoHaBTa
Copy link

If you are interested about a temporary workaround, while we wait for this to be implemented, you can do the following:

  1. Build and run your app on a device trough Xcode
  2. Go to your app's DerivedData folder -> Build/Products/Dev-iphoneos/{YOUR_APP_NAME}.app
  3. Copy the embedded.mobileprovision to your project and add it as a resource to the app - we need this, because the code here is trying to identify the environment form the provisioning profile which defaults to production if no profile is found , but the Simulator supports only the sandbox environment.
  4. Declare the following Objective-C Category in your code:

GULAppEnvironmentUtil+SimulatorPN.h

@import GoogleUtilities_Environment;
@interface GULAppEnvironmentUtil (SimulatorPN)
@end

GULAppEnvironmentUtil+SimulatorPN.m

#import "GULAppEnvironmentUtil+SimulatorPN.h"
#import <objc/runtime.h>

@implementation GULAppEnvironmentUtil (SimulatorPN)

+(void)load {
  Method original = class_getClassMethod([self class], @selector(isSimulator));
  Method swizzled = class_getClassMethod([self class], @selector(isSimulator_PN));
  method_exchangeImplementations(original, swizzled);
}

+ (BOOL)isSimulator_PN {
  return NO;
}

@end

Run your app in the Simulator and you will be able to receive push notifications from Firebase in the Simulator.

Keep in mind that the solution should only be applied when running in simulator.

@AlleSchonWeg
Copy link

If you are interested about a temporary workaround, while we wait for this to be implemented, you can do the following:

  1. Build and run your app on a device trough Xcode
  2. Go to your app's DerivedData folder -> Build/Products/Dev-iphoneos/{YOUR_APP_NAME}.app
  3. Copy the embedded.mobileprovision to your project and add it as a resource to the app - we need this, because the code here is trying to identify the environment form the provisioning profile which defaults to production if no profile is found , but the Simulator supports only the sandbox environment.
  4. Declare the following Objective-C Category in your code:

GULAppEnvironmentUtil+SimulatorPN.h

@import GoogleUtilities_Environment;
@interface GULAppEnvironmentUtil (SimulatorPN)
@end

GULAppEnvironmentUtil+SimulatorPN.m

#import "GULAppEnvironmentUtil+SimulatorPN.h"
#import <objc/runtime.h>

@implementation GULAppEnvironmentUtil (SimulatorPN)

+(void)load {
  Method original = class_getClassMethod([self class], @selector(isSimulator));
  Method swizzled = class_getClassMethod([self class], @selector(isSimulator_PN));
  method_exchangeImplementations(original, swizzled);
}

+ (BOOL)isSimulator_PN {
  return NO;
}

@end

Run your app in the Simulator and you will be able to receive push notifications from Firebase in the Simulator.

Keep in mind that the solution should only be applied when running in simulator.

Hi,
do you know the xamarin/c# variant for this workaround?

Thank you

@KoCMoHaBTa
Copy link

No idea, but the solution is using method swizzling. You can check if this can help you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: messaging type: feature request Xcode 14 - iOS 16 Issues and PRs related to Xcode 14, iOS 16, and associated OSes
5 participants