Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
OneTimeCode
-
@JonB yes symbol not found, then TypeError: expected 4 arguments, got 1 in
tfo.setTextContentType_(UIContentTypeOneTimeCode)
As I got early
-
@cvp can you print that line I had before to print the encoding?
-
or if encoding is not found, try
print(tfo.setTextContentType_.method_cache['0/'][0].encoding)
-
@JonB b'v0@0:0@"NSString"0'
-
@JonB print(tfo.setTextContentType_.method_cache['0/'][0].encoding)
AttributeError: 'ObjCInstanceMethod' object has no attribute 'method_cache' -
@JonB tfo.setTextContentType_(UIContentTypeOneTimeCode)
File "/var/containers/Bundle/Application/FED7F8B2-4F86-4833-BCFB-C2F8803CD0F1/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 874, in call
raise TypeError('expected %i arguments, got %i' % (len(argtypes) - 2, len(args)))
TypeError: expected 4 arguments, got 1 -
you might also try
tfo.setTextContentType_(UITextContentTypeOneTime, argtypes=[c_void_p], restype=None)
which should fix a botched encoding parse.
-
@JonB replaced by
tfo.setTextContentType_(UIContentTypeOneTimeCode, argtypes=[c_void_p], restype=None)
Then crash
Fatal Python error: Aborted Current thread 0x000000016fd07000 (most recent call first): File "/var/containers/Bundle/Application/FED7F8B2-4F86-4833-BCFB-C2F8803CD0F1/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 897 in __call__ File "/private/var/mobile/Containers/Shared/AppGroup/668A7D98-7216-47ED-917D-AA0B6173167E/Pythonista3/Documents/MesTests/test6.py", line 12 in <module> ------------------------------------------------------------------------ Objective-C exception details: NSInvalidArgumentException: -[UITextField String"]: unrecognized selector sent to instance 0x103a99c00 Stack trace: 0 CoreFoundation 0x00000001ee36feb8 <redacted> + 252 1 libobjc.A.dylib 0x00000001ed541a40 objc_exception_throw + 56 2 CoreFoundation 0x00000001ee288d04 <redacted> + 0 3 UIKitCore 0x000000021b162b38 <redacted> + 280 4 CoreFoundation 0x00000001ee3757b8 <redacted> + 1412 5 CoreFoundation 0x00000001ee37745c _CF_forwarding_prep_0 + 92 6 Py3Kit 0x00000001013f0044 ffi_call_SYSV + 68 7 Py3Kit 0x00000001013ebe10 ffi_call_int + 940 8 Py3Kit 0x00000001013e68bc _ctypes_callproc + 700 9 Py3Kit 0x00000001013e0178 PyCFuncPtr_call + 524 10 Py3Kit 0x0000000101210794 PyObject_Call + 124 11 Py3Kit 0x00000001012d9f24 _PyEval_EvalFrameDefault + 12284 12 Py3Kit 0x00000001012dd818 _PyEval_EvalCodeWithName + 3132 13 Py3Kit 0x00000001012de160 _PyFunction_FastCallDict + 340 14 Py3Kit 0x00000001012109bc _PyObject_FastCallDict + 304 15 Py3Kit 0x0000000101210ae4 _PyObject_Call_Prepend + 148 16 Py3Kit 0x0000000101210794 PyObject_Call + 124 17 Py3Kit 0x0000000101270c5c slot_tp_call + 180 18 Py3Kit 0x0000000101210970 _PyObject_FastCallDict + 228 19 Py3Kit 0x0000000101210dbc _PyObject_FastCallKeywords + 192 20 Py3Kit 0x00000001012dcabc call_function + 428 21 Py3Kit 0x00000001012d92c4 _PyEval_EvalFrameDefault + 9116 22 Py3Kit 0x00000001012dd818 _PyEval_EvalCodeWithName + 3132 23 Py3Kit 0x00000001012d6e9c PyEval_EvalCode + 56 24 Py3Kit 0x00000001013061c4 PyRun_FileExFlags + 188 25 Py3Kit 0x0000000101305658 PyRun_SimpleFileExFlags + 252 26 Py3Kit 0x0000000100bac174 -[PYK3Interpreter doRunWithOptions:] + 1176 27 Foundation 0x00000001eee2239c <redacted> + 336 28 CoreFoundation 0x00000001ee3001cc <redacted> + 24 29 CoreFoundation 0x00000001ee30014c <redacted> + 88 30 CoreFoundation 0x00000001ee2ffa30 <redacted> + 176 31 CoreFoundation 0x00000001ee2fa8fc <redacted> + 1040 32 CoreFoundation 0x00000001ee2fa1cc CFRunLoopRunSpecific + 436 33 Foundation 0x00000001eecef404 <redacted> + 300 34 Foundation 0x00000001eecef2b0 <redacted> + 148 35 Py3Kit 0x0000000100baabb0 -[PYK3Interpreter setupInterpreterThreadRunLoop] + 252 36 Foundation 0x00000001eee221ac <redacted> + 1040 37 libsystem_pthread.dylib 0x00000001edf8b2ac <redacted> + 128 38 libsystem_pthread.dylib 0x00000001edf8b20c _pthread_start + 48 39 libsystem_pthread.dylib 0x00000001edf8ecf4 thread_start + 4 End of exception details.```
-
you might also need a load_framework('UIKit') before defining the constant via in_dll
-
load_framework('UIKit') UIContentTypeOneTimeCode=c_void_p.in_dll(c, 'UIContentTypeOneTimeCode')
Gives
UIContentTypeOneTimeCode=c_void_p.in_dll(c, 'UIContentTypeOneTimeCode') ValueError: dlsym(RTLD_DEFAULT, UIContentTypeOneTimeCode): symbol not found
Thus I use
UIContentTypeOneTimeCode=ns('UIContentTypeOneTimeCode')
As you adviced
-
@JonB could you remember me the meaning of
b'v0@0:0@"NSString"0'
-
Yeah, objc_util gets confused with that.
Restart pyrhonista and try again - the argtypes/restype keywords only work the first time the uiinstancemethod is created I think.Can you try
c_void_p.in_dll(c,'UITextContentTypeURL')An see if it complains about symbol not found?
-
@JonB at each crash, I remove Pythonista from tasks list and restart...
-
Whoops, I think I mistyped before the symbol for one time code should be
UITextContentTypeOneTimeCode
In the in_dll. I had missed the Text bit
-
@JonB with UITextContentTypeOneTimeCode, no more symbol not found but same crash...
-
Ok, now when you call setTextContentType_(UITextContentTypeOneTimeCode, restype=c_void_p, argtypes=[c_void_p])
I had swapped restype and argtypes, it's possible both were needed
-
@JonB just to be sure, my "last" code is
import ui from objc_util import * load_framework('UIKit') UITextContentTypeOneTimeCode=c_void_p.in_dll(c, 'UITextContentTypeOneTimeCode') #UITextContentTypeOneTimeCode=ns('UITextContentTypeOneTimeCode') if UITextContentTypeOneTimeCode: UITextContentTypeOneTimeCode = ObjCInstance(UITextContentTypeOneTimeCode) tf = ui.TextField() tfo=tf.objc_instance.textField() print(tfo.setTextContentType_.encoding) tfo.setTextContentType_(UITextContentTypeOneTimeCode, argtypes=[c_void_p], restype=None) tf.present('sheet')
-
@JonB same crash ( my last code had been written just before your post about swapping, but I also tested it)
#tfo.setTextContentType_(UITextContentTypeOneTimeCode, argtypes=[c_void_p], restype=None) tfo.setTextContentType_(UITextContentTypeOneTimeCode, restype=c_void_p, argtypes=[c_void_p])
-
Sorry, right. Swap restype and argtypes order in the last call, and use restype=c_void_p.
Alternatively we could try
my_method = ObjCInstanceMethod(tfo, 'setTextContentType_') my_method.encoding='v@:@'
my_method(UITextContentTypeOneTimeCode)
-
@JonB same crash with
#tfo.setTextContentType_(UITextContentTypeOneTimeCode, argtypes=[c_void_p], restype=None) #tfo.setTextContentType_(UITextContentTypeOneTimeCode, restype=c_void_p, argtypes=[c_void_p]) my_method = ObjCInstanceMethod(tfo, 'setTextContentType_') my_method.encoding='v@:@' my_method(UITextContentTypeOneTimeCode)