#Share::url() doing nothing
1 messages ยท Page 1 of 1 (latest)
Any ideas @mortal notch
@marsh narwhal I recently just implemented share on my livewire app running v2 with no issues. Can you share a code snippet?
Sure I have the following function called share():
``<?php
namespace App\Livewire\Pages;
use App\Enums\DataSyncStatus;
use Livewire\Component;
use Native\Mobile\Facades\SecureStorage;
use Native\Mobile\Facades\Share;
class Home extends Component
{
public bool $dataSyncAvailable = false;
public DataSyncStatus $dataSyncStatus;
public function mount()
{
// check for data sync availability
$this->dataSyncStatus = DataSyncStatus::tryFrom(
function_exists('nativephp_call')
? SecureStorage::get('last_sync_status', DataSyncStatus::UNKNOWN->value)
: session()->get('last_sync_status', DataSyncStatus::UNKNOWN->value)
) ?? DataSyncStatus::UNKNOWN;
}
public function share()
{
if (function_exists('nativephp_call')) {
Share::url(
title: 'Paddle Log',
text: 'Check out Paddle Log - the app to log and track all your paddling adventures!',
url: 'https://paddlelog.online'
);
} else {
return redirect()->to('https://paddlelog.online/');
}
}
public function render()
{
return view('livewire.pages.home');
}
}``
Its run from
<a wire:click="share" class="cursor-pointer"> @include('livewire.components.widget', [ 'icon' => 'heroicon-s-share', 'title' => 'Share app with friends', 'class' => 'bg-slate-600 dark:bg-slate-800/50', ]) </a>
Which is running the function as I can put other calls in it (such as dd() for instance)
Have you been able to confirm that code inside the if (function_exists('nativephp_call')) { is running? Based on the code it seems like you're using this code both for the web and for the app?
Yeah I can place anywhere in it and it will run.
I'll pull the log files and see what is happening.
Revisting this one, I am getting:
01-18 21:02:56.758 980 1531 I BridgeJNI: ๐ BridgeJNI: NativePHPCall called with function='Share.Url'
01-18 21:02:56.758 980 1531 E BridgeRouter: โ Function 'Share.Url' not found
@mortal notch This is one for you again
This is my code:
``
try {
$result = Share::url(
title: 'Paddle Log',
text: 'Check out Paddle Log - the app to log and track all your paddling adventures!',
url: 'https://paddlelog.online'
);
// If Share.url doesn't work (returns null), fall back to browser
if ($result === null) {
throw new \Exception('Share function not available');
}
} catch (\Exception $e) {
// Fallback to browser if share doesn't work
Notification::make()
->title('Sharing not supported on this device, opening in browser instead.')
->warning()
->send();
Browser::inApp('https://paddlelog.online/');
}
``