EddyVerbruggen / Custom-URL-scheme

:link: Launch your Cordova/PhoneGap app by a Custom URL scheme like mycoolapp://
1.03k stars 365 forks source link

Support for multiple URL schemes #286

Closed markfeimer closed 5 years ago

markfeimer commented 5 years ago

I have a use case that involves support for multiple URL schemes. It looks like the *.plist file supports multiple URL schemes since the element is an array. Is there a recommended way to add multiple URL schemes via the plugin?

markfeimer commented 5 years ago

I ended up having to implement a custom solution since it didn't look like the plugin supported my use case. And so I don't uselessly frustrate somebody in the future, here's the bash script with plistbuddy that I use during the build step:

function setURLSchemes() {

    echo "setURLSchemes"
    declare -a urlSchemes=("com.foo.bar" "arbitrary.app.id" "noperiodsworkstoo")

    # shouldn't be needed, but the script will fail if this value already exists
    # ${PlistBuddy} -c "Delete :CFBundleURLTypes" ${pListPath}

    ${PlistBuddy} -c "Add :CFBundleURLTypes array" ${pListPath}
    ${PlistBuddy} -c "Add :CFBundleURLTypes:0 dict" ${pListPath}
    ${PlistBuddy} -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" ${pListPath}

    for i in "${urlSchemes[@]}"
    do
      ${PlistBuddy} -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string ${i}" ${pListPath}
    done

}