0

I am trying to setup an API endpoint my mobile app can use to redirect to Google Play or Apple App Store depending on the device making the request. I have php code that was working stand alone and have created an endpoint in my module that accepts an anonymous GET request.

How do I pass a custom header via the API response, or does this need to be done with a controller?

class AppStore implements AppStoreInterface {

    /**
     * {@inheritdoc}
     */

    public function appstore()
    {
        // android store
        if (preg_match('#android#i', $_SERVER ['HTTP_USER_AGENT'])) {
            header('Location: market://details?id=com.google.android.apps.maps/...');
            return "android";
        }
        // ios
        if (preg_match('#(iPad|iPhone|iPod)#i', $_SERVER ['HTTP_USER_AGENT'])) {
            header('Location: itms://itunes.apple.com/us/app/....');
            return "ios";
        }
        // for another os
        return "Not supported";
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.