PHP code example of blutrixx / nativephp-mobile-updater

1. Go to this page and download the library: Download blutrixx/nativephp-mobile-updater library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blutrixx / nativephp-mobile-updater example snippets


use Blutrixx\MobileUpdater\Facades\MobileUpdater;

$installed = MobileUpdater::checkVersion();

MobileUpdater::download(
    url: 'https://updates.example.com/apps/myapp/2.1.0.apk',
    expectedSize: 41_943_040,
    sha256: 'a1b2c3...',
);

$status = MobileUpdater::checkDownloadStatus();
if ($status['ready']) {
    MobileUpdater::installApk();
}

// routes/api.php
Route::get('/app/check-update', function () {
    $installed = \Blutrixx\MobileUpdater\Facades\MobileUpdater::checkVersion();
    $manifest  = Http::get(config('services.updates.manifest_url'))->json();

    return [
        'installed' => $installed,
        'latest'    => $manifest['latestVersion'],
        'update'    => $manifest['versions'][0] ?? null,
    ];
});

Route::post('/app/start-update', function (Request $request) {
    return \Blutrixx\MobileUpdater\Facades\MobileUpdater::download(
        url: $request->string('apkUrl'),
        expectedSize: $request->integer('size'),
        sha256: $request->string('checksum')->after('sha256:'),
    );
});

Route::post('/app/install-update', fn () => \Blutrixx\MobileUpdater\Facades\MobileUpdater::installApk());