iOS Question [Solved] Problems with NativeObject

angel_

Well-Known Member
Licensed User
Longtime User
How can I use NativeObject with B4XPages in this code?:

B4X:
Private no As NativeObject = Me
   
Log(no.RunMethod("deviceName", Null).AsString)
Log(no.Initialize("NSLocale").RunMethod("preferredLanguages", Null).RunMethod("objectAtIndex:", Array(0)).AsString)
Log(no.RunMethod("deviceName", Null).AsString)
Log(no.Initialize("NSBundle").RunMethod("mainBundle", Null).RunMethod("objectForInfoDictionaryKey:", Array("CFBundleDisplayName")).AsString)
 

roumei

Active Member
Licensed User
It works for me if I add no = Me after the first no.Initialize and if the OBJC code for deviceName is added at the end.
B4X:
Dim no As NativeObject = Me
Log(no.RunMethod("deviceName", Null).AsString)
Log(no.Initialize("NSLocale").RunMethod("preferredLanguages", Null).RunMethod("objectAtIndex:", Array(0)).AsString)
no = Me
Log(no.RunMethod("deviceName", Null).AsString)
Log(no.Initialize("NSBundle").RunMethod("mainBundle", Null).RunMethod("objectForInfoDictionaryKey:", Array("CFBundleDisplayName")).AsString)
B4X:
Application_Start
iPhone 8 Plus (GSM)
de-DE
iPhone 8 Plus (GSM)
B4i Example
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Application_Active
The OBJC-Code is here: Get iPhone Model | B4X Programming Forum
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
I have this error

B4X:
Copying updated assets files (1)
Application_Start
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Application_Active
Error occurred on line: 27 (B4XMainPage)
Method not found: deviceName, target: [_root=<B4XViewWrapper: <B4IPanelView: 0x153d14610; frame = (0 0; 736 370); layer = <CALayer: 0x281fac740>>>, _xui=<B4IXUI: 0x281db1970>, _main=<b4i_main: (null)>
, _b4xpages=<b4i_b4xpages: (null)>, _b4xcollections=<b4i_b4xcollections: (null)>]
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  B4i Example          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 368
  B4i Example          -[B4INativeObject RunMethod::] + 216
  B4i Example          -[b4i_b4xmainpage _button1_click:] + 708
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
  B4i Example          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
  B4i Example          -[B4IShell runMethod:] + 448
 B4i Example          -[B4IShell raiseEventImpl:method:args::] + 1648
 B4i Example          -[B4IShellBI raiseEvent:event:params:] + 1580
 B4i Example          __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
 libdispatch.dylib    <redacted> + 24
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 1068
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 1924
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 104
 UIKitCore            UIApplicationMain + 212
 B4i Example          main + 128
 libdyld.dylib        <redacted> + 4
)
 
Upvote 0

roumei

Active Member
Licensed User
Where do you call the code? Try to run it in B4XPage_Created and see what happens or post the rest of your code so we can have a look.
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
With a button in B4XMainPage

B4X:
Private Sub Button1_Click
    Dim no As NativeObject = Me
    Log(no.RunMethod("deviceName", Null).AsString)
    Log(no.Initialize("NSLocale").RunMethod("preferredLanguages", Null).RunMethod("objectAtIndex:", Array(0)).AsString)
    no = Me
    Log(no.RunMethod("deviceName", Null).AsString)
    Log(no.Initialize("NSBundle").RunMethod("mainBundle", Null).RunMethod("objectForInfoDictionaryKey:", Array("CFBundleDisplayName")).AsString)
End Sub
 

Attachments

  • RunMethod.zip
    2.8 KB · Views: 239
Upvote 0
Top