Unity3d request user authorisation (OSX)

雨燕双飞 提交于 2019-12-25 06:08:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!