angular 7 pwa manifest dynamically

Discussão em 'Angular' iniciado por vDrews, Julho 6, 2025.

  1. vDrews

    vDrews Guest

    I have created a PWA with Angular 6. Later I want to have different Icons and start Urls, since the app will be running under multiple urls (each account will be assigned a unique url and each of them have different logos). So I want to change the manifest.json dynamically.

    Is there a way to do that?

    Edit:

    I try it like this:

    <head>
    <meta charset="utf-8">
    <title>Pwatest</title>
    <base href="/">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="assets/icons/coffee.png">
    <link rel="manifest" id="my-manifest-placeholder">
    <link rel="apple-touch-icon" href="assets/icons/icon-192x192.png">
    <!-- <link rel="manifest" href="manifest.json"> -->
    <meta name="theme-color" content="#1976d2">

    <script>
    var test = true;

    var myDynamicManifest = {
    "name": "pwatest",
    "short_name": "pwatest",
    "theme_color": "#1976d2",
    "background_color": "#fafafa",
    "display": "standalone",
    "scope": "/",
    "start_url": "/",
    "icons": []
    }

    if(test){
    myDynamicManifest['icons'].push({
    "src": "assets/icons/coffee-192x192.png",
    "sizes": "192x192",
    "type": "image/png"
    });
    }else{
    myDynamicManifest['icons'].push({
    "src": "assets/icons/frog-192x192.png",
    "sizes": "192x192",
    "type": "image/png"
    });
    }

    console.log(myDynamicManifest);
    const stringManifest = JSON.stringify(myDynamicManifest);
    const blob = new Blob([stringManifest], {type: 'application/json'});
    const manifestURL = URL.createObjectURL(blob);

    document.querySelector('#my-manifest-placeholder').setAttribute('href', manifestURL);
    console.log(document.querySelector('#my-manifest-placeholder'));
    </script>

    </head>


    [​IMG]

    Edit2:

    I don't found a solution. I try it like this now:

    index.html

    <link rel="manifest" id="my-manifest-placeholder" href="/manifest.php">


    manifest.php

    <?php
    $test = [
    "name" => "pwatest",
    "gcm_user_visible_only" => true,
    "short_name" => "pwatest",
    "start_url" => "/",
    "display" => "standalone",
    "orientation" => "portrait",
    "background_color" => "#fafafa",
    "theme_color" => "#1976d2",
    "icons" => [
    "src" => "assets/icons/coffee-192x192.png",
    "sizes"=> "192x192",
    "type" => "image/png"
    ]
    ];

    header('Content-Type: application/json');
    echo json_encode($test);
    ?>


    but I become the full php file not a JSON.

    can I do it like this?

    Continue reading...

Compartilhe esta Página