So I tried to add the delegate and added the fault handler. With the init removed it crashes when assigning the delegate.
Here is my code:
from __future__ import absolute_import, division, print_function
from objc_util import *
from pythonista_startup.enable_faulthandler import run
load_framework('HomeKit')
def homeManagerDidUpdateHomes(self, cmd):
print('homeManagerDidUpdateHomes')
methods = [homeManagerDidUpdateHomes]
protocols = ['HMHomeManagerDelegate']
MyHMHomeManagerDelegate = create_objc_class('MyHMHomeManagerDelegate',NSObject,methods=methods,protocols=protocols)
def main():
print('Start of script')
# run enable faulthandler
run()
myHMHomeManagerDelegate = MyHMHomeManagerDelegate.alloc()
HMHomeManager = ObjCClass('HMHomeManager')
homemanager = HMHomeManager.alloc()
homemanager.setDelegate(myHMHomeManagerDelegate)
print('End of script')
if __name__ == '__main__':
main()
NOTE: The objc delegate method is:
- (void)homeManagerDidUpdateHomes:(HMHomeManager *)manager;
When I tried to define the python delegate method as def homeManagerDidUpdateHomes(self, cmd,manager): I got an error that the method was only expecting 2 parameters but found 3.
Back to the code... as mentioned I first ran with the line to set the delegate which crashed so I then commented out the set delegate line to let it complete successfully. The fault handler outputted the following:
Start of script
Enabling fault handler and Objective-C exception handler...
Pythonista quit abnormally last time.
For details, see the following log file: faultlog-2018-02-19-14-36-24.txt
Setting fault handler.
Done enabling fault handler and Objective-C exception handler.
End of script
The contents of the fault log
Fatal Python error: Segmentation fault
Current thread 0x000000016f72b000 (most recent call first):
File "/var/containers/Bundle/Application/31989ED7-8359-46ED-90D1-AA84E7A73FA8/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 897 in call
File "/var/containers/Bundle/Application/31989ED7-8359-46ED-90D1-AA84E7A73FA8/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 803 in call
File "/private/var/mobile/Containers/Shared/AppGroup/0ED4DCFF-B233-4C51-A9EF-89FAA67A9C87/Pythonista3/Documents/Test01/HomeKit03.py", line 21 in main
File "/private/var/mobile/Containers/Shared/AppGroup/0ED4DCFF-B233-4C51-A9EF-89FAA67A9C87/Pythonista3/Documents/Test01/HomeKit03.py", line 25 in
Here is the fault log when using alloc().init()
Fatal Python error: Aborted
Thread 0x000000016b577000 (most recent call first):
I also tried .delegate = instead of setDelegate which crashed with the following log
Fatal Python error: Segmentation fault
Current thread 0x000000016f8a3000 (most recent call first):
File "/var/containers/Bundle/Application/31989ED7-8359-46ED-90D1-AA84E7A73FA8/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 897 in call
File "/var/containers/Bundle/Application/31989ED7-8359-46ED-90D1-AA84E7A73FA8/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 650 in setattr
File "/private/var/mobile/Containers/Shared/AppGroup/0ED4DCFF-B233-4C51-A9EF-89FAA67A9C87/Pythonista3/Documents/Test01/HomeKit03.py", line 22 in main
File "/private/var/mobile/Containers/Shared/AppGroup/0ED4DCFF-B233-4C51-A9EF-89FAA67A9C87/Pythonista3/Documents/Test01/HomeKit03.py", line 26 in
Thanks for the help.