最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

React Native Windows: C++ UWP - How to open a folder : LaunchFolderAsync-> (A method was called at an unexpected time) -

matteradmin3PV0评论

I cannot open a folder to windows explorer using a native module (C++ UWP).

I tried following the appropriate manner UWP C++

StorageFolder folder{ co_await StorageFolder::GetFolderFromPathAsync(filePath) };
OutputDebugStringW(L"openFolder StorageFolder passed.\n");
bool launched = co_await Launcher::LaunchFolderAsync(folder); // <-Error happened
...
catch (const winrt::hresult_error& ex)
{
    std::wstringstream ss;
    ss << L"[openFolder] Error: " << ex.message().c_str() << L"\n";
    OutputDebugStringW(ss.str().c_str());

    promise.Resolve(false);
    co_return;
}

I get an error when I click on the button in the interface of the React-Native Windows app (the app is active and in focused). I run the app using "npx react-native start --reset-cache" and "npx react-native run-windows".

I get the fabulous error (DebugView) :

Error: A method was called at an unexpected time.

I tried normalising the path before doing the StorageFolder does not change the outcome.

I also tried "ShellExecuteW" but no luck on this side. I would prefer to use the approved method for UWP.

My manifest has "<rescap:Capability Name="broadFileSystemAccess"/>" and I tried adding "<rescap:Capability Name="runFullTrust" />" same result. The app is authorised in the Privacy settings for filesystem and I read and write files outside approved UWP folders without any issues.

I tried to open different locations and I always get that error.

Any help would be much appreciated.

Edit: I tried to integrate it as a button in the UI and click manually on the button to trigger the call like that :

const CustomModule: {
    openFolder(filePath: string): Promise<boolean>;
  } = NativeModules.NativeReactModule;

Then in memo :

<View key={key}><Button title="Open" onPress={() => onRowButtonPressOpenFolder(item)} /></View>

Finally :

const onRowButtonPressOpenFolder = useCallback(async () => {const openFolder: any = await CustomModule.openFolder(route.params.folder);}, []);

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far