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
-
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)
-
Ate you sure the traceback is the exactly the same? What is the invalid selector now?
Try using : instead of _ in the selector name... I forget how objcinstancemsthod works
-
@JonB 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 = ObjCInstanceMethod(tfo, 'setTextContentType:') my_method.encoding='v@:@' my_method(UITextContentTypeOneTimeCode)
Fault log is
Fatal Python error: Aborted Current thread 0x000000016ff97000 (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 22 in <module> ------------------------------------------------------------------------ Objective-C exception details: NSInvalidArgumentException: -[UITextField String"]: unrecognized selector sent to instance 0x104289c00 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 0x0000000101468044 ffi_call_SYSV + 68 7 Py3Kit 0x0000000101463e10 ffi_call_int + 940 8 Py3Kit 0x000000010145e8bc _ctypes_callproc + 700 9 Py3Kit 0x0000000101458178 PyCFuncPtr_call + 524 10 Py3Kit 0x0000000101288794 PyObject_Call + 124 11 Py3Kit 0x0000000101351f24 _PyEval_EvalFrameDefault + 12284 12 Py3Kit 0x0000000101355818 _PyEval_EvalCodeWithName + 3132 13 Py3Kit 0x0000000101356160 _PyFunction_FastCallDict + 340 14 Py3Kit 0x00000001012889bc _PyObject_FastCallDict + 304 15 Py3Kit 0x0000000101288ae4 _PyObject_Call_Prepend + 148 16 Py3Kit 0x0000000101288794 PyObject_Call + 124 17 Py3Kit 0x00000001012e8c5c slot_tp_call + 180 18 Py3Kit 0x0000000101288970 _PyObject_FastCallDict + 228 19 Py3Kit 0x0000000101354abc call_function + 428 20 Py3Kit 0x00000001013527b4 _PyEval_EvalFrameDefault + 14476 21 Py3Kit 0x0000000101355818 _PyEval_EvalCodeWithName + 3132 22 Py3Kit 0x000000010134ee9c PyEval_EvalCode + 56 23 Py3Kit 0x000000010137e1c4 PyRun_FileExFlags + 188 24 Py3Kit 0x000000010137d658 PyRun_SimpleFileExFlags + 252 25 Py3Kit 0x0000000100c24174 -[PYK3Interpreter doRunWithOptions:] + 1176 26 Foundation 0x00000001eee2239c <redacted> + 336 27 CoreFoundation 0x00000001ee3001cc <redacted> + 24 28 CoreFoundation 0x00000001ee30014c <redacted> + 88 29 CoreFoundation 0x00000001ee2ffa30 <redacted> + 176 30 CoreFoundation 0x00000001ee2fa8fc <redacted> + 1040 31 CoreFoundation 0x00000001ee2fa1cc CFRunLoopRunSpecific + 436 32 Foundation 0x00000001eecef404 <redacted> + 300 33 Foundation 0x00000001eecef2b0 <redacted> + 148 34 Py3Kit 0x0000000100c22bb0 -[PYK3Interpreter setupInterpreterThreadRunLoop] + 252 35 Foundation 0x00000001eee221ac <redacted> + 1040 36 libsystem_pthread.dylib 0x00000001edf8b2ac <redacted> + 128 37 libsystem_pthread.dylib 0x00000001edf8b20c _pthread_start + 48 38 libsystem_pthread.dylib 0x00000001edf8ecf4 thread_start + 4 End of exception details.
-
ok, try
my_method = ObjCInstanceMethod(tfo, 'setTextContentType_') my_method.sel_name='setTextContentType:' my_method.encoding=b'v@:@' my_method(UITextContentTypeOneTimeCode)
i forgot encoding should be bytes, not str. and lets try setting the selName manually.
that should do it.....?
-
@JonB Sorry for the delay, dinner time 😢
No crash but how to check if script ok: keyboard of tf seems usual... -
Now THAT I don't know...
what does tfo.textContentType() return?
I think you'd have to text yourself from another phone with a text that has a code. Then you might need to have the auto correct/suggestion thing above the keyboard enabled, and it should show the code as a suggestion.
-
@JonB return is None.
Hoping all this spent time will help @AlbertoAEC -
From stack overflow
First of all, the SMS need to have the keyword "code" or "passcode" into their message, and don't use spaces after the code. if you received the SMS and you have the button "Copy Code" then it will works
-
@cvp are you on ios12?
Seems like this didn't actually work...
-
@JonB iOS 12.1, but don't forget I am not the requester. I only tried to help, without success if without you 😢
-
@cvp @JonB THANK YOU VERY MUCH!!
It works perfectly.
You can try the code using other content type like phone number.
UITextContentTypeTelephoneNumberimport ui from objc_util import * load_framework('UIKit') UITextContentTypeOneTimeCode=c_void_p.in_dll(c, 'UITextContentTypeTelephoneNumber') if UITextContentTypeOneTimeCode: UITextContentTypeOneTimeCode = ObjCInstance(UITextContentTypeOneTimeCode) tf = ui.TextField() tf.keyboard_type = ui.KEYBOARD_NUMBER_PAD tfo=tf.objc_instance.textField() print(tfo.setTextContentType_.encoding) my_method = ObjCInstanceMethod(tfo, 'setTextContentType_') my_method.sel_name='setTextContentType:' my_method.encoding=b'v@:@' my_method(UITextContentTypeOneTimeCode) tf.present('sheet')
I couldn’t answer to you before because I was working.
Best regards,
Alberto -
@AlbertoAEC 👍 and one proof more, if needed, that @JonB is our guru
-
@AlbertoAEC and you can comment the load_framework, I think
#load_framework('UIKit')
-
@cvp yes, load_framework is no needed.
Thanks to both of you for your time