Repository: flutter
Issue: FlutterCallbackCache.lookupCallbackInformation returns nil
Labels: platform-ios,engine,P2,team-ios,triaged-ios

My goal is to start the flutter engine and run some dart code from a Notification Service Extension on iOS to prepare my app before the user receives a push notification.

Issue is `FlutterCallbackCache.lookupCallbackInformation(callbackHandle)` returns `nil`
The callback handle integer is generated (fetched in dart), stored in UserDefaults and retrieved correctly, I have printed out the value all the way through and it is identical.

But it appears that when running in the service extension the FlutterCallbackCache does not have any value for that handle.
Storing into the FlutterCallbackCache is handled automatically by flutter when you retrieve the handle originally (calling `PluginUtilities.getCallbackFromHandle(...)` so there cannot be any user error there.

Documentation on this topic is very limited. But I can only assume this is a bug to do with the additional complexity of running in a service extension. Some scope issue maybe?

### Steps to reproduce
Call FlutterCallbackCache.lookupCallbackInformation from a iOS Notification Service Extension

### Expected results

FlutterCallbackCache.lookupCallbackInformation should return FlutterCallbackInformation

### Actual results

FlutterCallbackCache.lookupCallbackInformation returns nil

### Code sample

<details open><summary>Code sample</summary>

```swift
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.logger.log("NotificationPreSync Service Extension called")

        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
        
        var dict = NotificationPreSyncUserDefaultsHelper.userDefaults.dictionaryRepresentation().values
        print(dict)
                
        guard let callbackHandle = NotificationPreSyncUserDefaultsHelper.getStoredCallbackHandle()
        else {
            self.logger.log("[\(String(describing: self))] no callback handle stored")
            
            serviceExtensionTimeWillExpire()
            return
        }

        guard let flutterCallbackInformation = FlutterCallbackCache.lookupCallbackInformation(callbackHandle)
        else {
            //flutterCallbackInformation is nil so function exits through here.
            self.logger.log("[\(String(describing: self))] cannot look up callback information")
            
            serviceExtensionTimeWillExpire()
            return
        }
...
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>
<img width="1751" alt="Screenshot 2024-10-08 at 1 39 23 PM" src="https://github.com/user-attachments/assets/8a8eed74-5bf5-4082-a578-c672ef2585a7">


</details>


### Logs

```
request	UNNotificationRequest	0x000000010808ca20
contentHandler	() -> ()	0x0000000104b568b8 NotificationPreSync.debug.dylib`partial apply forwarder for reabstraction thunk helper from @escaping @callee_unowned @convention(block) (@unowned __C.UNNotificationContent) -> () to @escaping @callee_guaranteed (@guaranteed __C.UNNotificationContent) -> () at <compiler-generated>
self	NotificationPreSync.NotificationService	0x000000010813da40
UserNotifications.UNNotificationServiceExtension	UNNotificationServiceExtension	
contentHandler	((UNNotificationContent) -> ())?	0x0000000104b568b8 NotificationPreSync.debug.dylib`partial apply forwarder for reabstraction thunk helper from @escaping @callee_unowned @convention(block) (@unowned __C.UNNotificationContent) -> () to @escaping @callee_guaranteed (@guaranteed __C.UNNotificationContent) -> () at <compiler-generated>
bestAttemptContent	UNMutableNotificationContent?	0x000000010818c8c0
backgroundEngine	FlutterEngine?	nil	none
TAG	String	"DartFcmBackgroundExecutor"	
logger	os.Logger	
dict	[String : Any].Values	
callbackHandle	Int64	-5894632265597711899
exampleShowingNil	FlutterCallbackInformation?	nil	none
```

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.6.1 23G93 darwin-arm64, locale en-NZ)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Android Studio (version 2023.3)
[✓] IntelliJ IDEA Community Edition (version 2024.2.1)
[✓] VS Code (version 1.90.0)
[✓] VS Code (version 1.94.0)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

```

</details>