I wrote a script and everything worked will when run by python.
import objc
from CoreLocation import CLLocationManager
import logging
location_manager = CLLocationManager.alloc().init()
location_manager.requestWhenInUseAuthorization()
logger = logging.getLogger()
logger.setLevel(logging.INFO)
fh = logging.FileHandler('/Users/xpeng/Downloads/logging.log')
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger.addHandler(fh)
logger.addHandler(ch)
if __name__ == '__main__':
bundle_path = '/System/Library/Frameworks/CoreWLAN.framework'
objc.loadBundle('CoreWLAN',
bundle_path=bundle_path,
module_globals=globals())
iface = CWInterface.interface()
logger.info(str(iface.interfaceName()))
logger.info(iface.ssid())
networks, error = iface.scanForNetworksWithSSID_error_(None, None)
for network in networks:
logger.info(network.ssid())
But after I pyinstaller -w -F test.py and excute sudo open path_to_app, the log was like
2024-03-13 18:10:51,931 - root - INFO - en1
2024-03-13 18:10:51,935 - root - INFO - None
2024-03-13 18:10:53,546 - root - INFO - None
2024-03-13 18:10:53,547 - root - INFO - None
2024-03-13 18:10:53,547 - root - INFO - None
2024-03-13 18:10:53,547 - root - INFO - None
2024-03-13 18:10:53,547 - root - INFO - None
2024-03-13 18:10:53,547 - root - INFO - None
2024-03-13 18:10:53,547 - root - INFO - None
2024-03-13 18:10:53,548 - root - INFO - None
2024-03-13 18:10:53,548 - root - INFO - None
2024-03-13 18:10:53,548 - root - INFO - None
2024-03-13 18:10:53,548 - root - INFO - None
2024-03-13 18:10:53,548 - root - INFO - None
2024-03-13 18:10:53,548 - root - INFO - None
2024-03-13 18:10:53,548 - root - INFO - None
2024-03-13 18:10:53,548 - root - INFO - None
2024-03-13 18:10:53,548 - root - INFO - None
2024-03-13 18:10:53,549 - root - INFO - None
2024-03-13 18:10:53,549 - root - INFO - None
2024-03-13 18:10:53,549 - root - INFO - None
2024-03-13 18:10:53,549 - root - INFO - None
I did grant test location permission in system preferences.
Is there any other thing must do before I pack?