flutter-unity-view-widget icon indicating copy to clipboard operation
flutter-unity-view-widget copied to clipboard

Value of type 'UnityAppController' has no member 'unityMessageHandler'

Open Ahmadre opened this issue 5 years ago • 12 comments

I can't RUN or Build ios because of this:

Bildschirmfoto 2021-10-28 um 20 14 44

Why is everytime a new bug appearing in this project?

Ahmadre avatar Oct 28 '21 18:10 Ahmadre

if self.ufw?.appController() != nil {
            controller = self.ufw?.appController()
            controller?.unityMessageHandler = self.unityMessageHandlers
            controller?.unitySceneLoadedHandler = self.unitySceneLoadedHandlers
            self.ufw?.appController()?.window?.windowLevel = UIWindow.Level(UIWindow.Level.normal.rawValue - CGFloat(globalUILevel))
        }
        _isUnityLoaded = true

Ahmadre avatar Oct 28 '21 18:10 Ahmadre

What should I use here?! @juicycleff

Bildschirmfoto 2021-10-28 um 20 15 59

Ahmadre avatar Oct 28 '21 18:10 Ahmadre

what is this other plugin that you speak of?

mkforty7 avatar Mar 08 '22 08:03 mkforty7

add:

Classes/UnityAppController.mm
- (void)application:(UIApplication*)application handleEventsForBackgroundURLSession:(nonnull NSString ...

+
// Added by https://github.com/juicycleff/flutter-unity-view-widget
extern "C" void OnUnityMessage(const char* message)
{
    if (GetAppController().unityMessageHandler) {
        GetAppController().unityMessageHandler(message);
    }
}

extern "C" void OnUnitySceneLoaded(const char* name, const int* buildIndex, const bool* isLoaded, const bool* IsValid)
{
    if (GetAppController().unitySceneLoadedHandler) {
        GetAppController().unitySceneLoadedHandler(name, buildIndex, isLoaded, IsValid);
    }
}

Classes/UnityAppController.h
@property (nonatomic, copy)                                 void (^quitHandler)(void);...
+
@property (nonatomic, copy)                                 void(^unitySceneLoadedHandler)(const char* name, const int* buildIndex, const bool* isLoaded, const bool* IsValid);
@property (nonatomic, copy)                                 void(^unityMessageHandler)(const char* message);

impayru avatar Jun 08 '22 11:06 impayru

add:

Classes/UnityAppController.mm
- (void)application:(UIApplication*)application handleEventsForBackgroundURLSession:(nonnull NSString ...

+
// Added by https://github.com/juicycleff/flutter-unity-view-widget
extern "C" void OnUnityMessage(const char* message)
{
    if (GetAppController().unityMessageHandler) {
        GetAppController().unityMessageHandler(message);
    }
}

extern "C" void OnUnitySceneLoaded(const char* name, const int* buildIndex, const bool* isLoaded, const bool* IsValid)
{
    if (GetAppController().unitySceneLoadedHandler) {
        GetAppController().unitySceneLoadedHandler(name, buildIndex, isLoaded, IsValid);
    }
}

Classes/UnityAppController.h
@property (nonatomic, copy)                                 void (^quitHandler)(void);...
+
@property (nonatomic, copy)                                 void(^unitySceneLoadedHandler)(const char* name, const int* buildIndex, const bool* isLoaded, const bool* IsValid);
@property (nonatomic, copy)                                 void(^unityMessageHandler)(const char* message);

This helped. Thanks a lot.

dmgcoding avatar Jul 27 '22 19:07 dmgcoding

Where do I add this exactly? Running in to this issue now

rickdijk avatar Nov 30 '22 16:11 rickdijk

You should add Unity Message Manager to your unity object first, then export. It solves my problem

TJRoger avatar Feb 28 '23 03:02 TJRoger

This actually worked @impayru thanks!!

@rickdijk and for others who need more details :

In ios/UnityLibrary/Classes/UnityAppController.mm after the function handleEventsForBackgroundURLSession add :

extern "C" void OnUnityMessage(const char* message)
{
    if (GetAppController().unityMessageHandler) {
        GetAppController().unityMessageHandler(message);
    }
}

extern "C" void OnUnitySceneLoaded(const char* name, const int* buildIndex, const bool* isLoaded, const bool* IsValid)
{
    if (GetAppController().unitySceneLoadedHandler) {
        GetAppController().unitySceneLoadedHandler(name, buildIndex, isLoaded, IsValid);
    }
}

In ios/UnityLibrary/Classes/UnityAppController.h after :

@property (nonatomic, copy) void (^quitHandler)(void);

Add :

@property (nonatomic, copy)                                 void(^unitySceneLoadedHandler)(const char* name, const int* buildIndex, const bool* isLoaded, const bool* IsValid);
@property (nonatomic, copy)                                 void(^unityMessageHandler)(const char* message);

MarkAlexanderDev avatar Mar 02 '23 08:03 MarkAlexanderDev

I just found a reliable way to replicate this error.

Reproduction

  • Set the build target in Unity build settings to anything NOT iOS, like Android or Desktop.
  • Now click Flutter-> Export iOS.

This results in an incomplete build, because any code in #if UNITY_IOS blocks is skipped. However you still see the build successful message.

The build script will change the buildtarget automatically, but somehow the #If UNITY_ keeps the old value.

Current solution

Change the Unity build target before clicking Flutter -> Export.

You don't have to paste any code like in the comments above, that should be done by the export script automatically.

If you use batchmode or command line, make sure to include -buildTarget iOS in your command.

timbotimbo avatar May 11 '23 10:05 timbotimbo

I am facing this exact issue, I have selected ios as the platform before clicking futter-> export the code provided @MarkAlexanderDev did the trick.

el-mimoso avatar Jul 20 '23 19:07 el-mimoso

I just found a reliable way to replicate this error.

Reproduction

* Set the build target in Unity build settings to anything NOT iOS, like Android or Desktop.

* Now click Flutter-> Export iOS.

This results in an incomplete build, because any code in #if UNITY_IOS blocks is skipped. However you still see the build successful message.

The build script will change the buildtarget automatically, but somehow the #If UNITY_ keeps the old value.

Current solution

Change the Unity build target before clicking Flutter -> Export.

You don't have to paste any code like in the comments above, that should be done by the export script automatically.

If you use batchmode or command line, make sure to include -buildTarget iOS in your command.

Thank you! This should be in the Troubleshooting section. One thing I would like to add to the solution, that is you need to close & reopen the Unity project first.

WillowWisp avatar Jan 25 '24 07:01 WillowWisp

Sometime when click Export Ios (Release) UnityController.h would change like this image And UNityController.mm file like this image After export Export Ios (Release) control this two files if it was changed rollback these

hafizramiz avatar Jul 10 '24 19:07 hafizramiz