问题
So basically my Unity program would need to modify hosts file on OSX and that need admin privilege. And i got the following Exception:
UnauthorizedAccessException: Access to the path "/private/etc/hosts" is denied.
How do I pop a "XXX wants to make changes: Enter your password to allow this." window just like the screenshot I attached below?
I did some Google but i couldn't find anything useful.
Any suggestion would be appreciated.
回答1:
Did some more research, the only solution I can think off right now is to write a native plugin using apple's Authorization service, and call it from Unity program.
But if there's a more Unity way of doing it, please don't hesitate to add it as an answer.
EDIT_1: Progress update and a note to my future self.
A native plugin for OSX is suffixed .bundle, I wrote it in C++(since the official example is in c++), but it dont have access to authorization service. And i don't know how to setup OC for a bundle project. Now I'm trying an alternative to create a command-line tool application for OS X and run it as an external process from Unity3d. Good news is now i can use swift to write it !
.
EDIT_2: Progress update and a note to my future self.
The commandline tool written in OC did work. I can simply open command line tool using Process.start(name, argument) in Unity3d.
来源:https://stackoverflow.com/questions/42443185/unity3d-request-user-authorisation-osx