iOS Question How to share a pdf file to social media functionality?

PierPaduan

Active Member
Licensed User
Longtime User
Hi All,

I tried the code of this post:
https://www.b4x.com/android/forum/t...elp-with-inline-objc.52849/page-6#post-336177

It works fine with local images, but the app crashes if I try to share a local pdf file.
B4X:
'strImagePath = File.DirAssets & "/image.png"
strImagePath = File.DirAssets & "/5.pdf"
"5.pdf" has been loaded in Files subdirectory of the project and has been added in Files Manager tab.

The error is:
Application_Start
Application_Active
Error occurred on line: 114 (modShare)
*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 428
CoreFoundation <redacted> + 44
Share Test -[b4i_modshare share2SocialMedia:::::] + 1392
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
Share Test +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
Share Test -[B4INativeObject RunMethod::] + 164
Share Test -[b4i_modshare _sharetosocialmedia:::::] + 2814
Share Test -[b4i_main _cmdsharelocalimage_click] + 1540
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
Share Test +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
Share Test -[B4IShell runMethod:] + 574
Share Test -[B4IShell raiseEventImpl:method:args::] + 1998
Share Test -[B4IShellBI raiseEvent:event:params:] + 1442
Share Test __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib <redacted> + 1322
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1512
CoreFoundation CFRunLoopRunSpecific + 476
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 136
UIKit UIApplicationMain + 1440
Share Test main + 106
libdyld.dylib <redacted> + 2
)

What I need to change to share a pdf?

Thanks to All.
 

PierPaduan

Active Member
Licensed User
Longtime User
Thanks Erel, but may be I don't apply correctly what you are suggesting.

I've changed:
B4X:
'strImagePath = File.DirAssets & "/image.png"
'strImagePath = File.DirAssets & "/5.pdf"
strImagePath = File.Combine(File.DirAssets, "5.pdf")

and changed:
B4X:
//image = [UIImage imageNamed:theimg];
image = [UIImage imageWithContentsOfFile:theimg];

But the error is still the same.

What ca I do?
 
Upvote 0

Descartex

Well-Known Member
Licensed User
Longtime User
You are trying to share a PDF file as an image... you have to share it as a binary i think...
 
Upvote 0
Top