iPhone WebApps, is there a way to detect how it was loaded? Home Screen vs Safari?

前端 未结 8 742
走了就别回头了
走了就别回头了 2020-12-02 07:56

I have an iPhone Web App, and I\'m interested in detecting if the app was loaded either from:

  1. iPhone Safari
  2. iPhone installed web app (via the add to m
8条回答
  •  天命终不由人
    2020-12-02 08:44

    I'm not sure how far back this behavior goes, but iOS will present different UserAgent strings to the server which can be used to detect if the page is being requested by a webapp or safari browser.

    Safari Browser

    Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B436 Safari/600.1.4

    Home Screen Button/Web App

    Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B436

    Notice it does not include 'Safari' in the UserAgent. I've confirmed that this behavior goes back to at least iOS 7, but I'd imagine even further.

    So you can test for the presence of iPhone or iPad in the UserAgent string and lack of Safari to detect that it's been opened from the Home screen.

提交回复
热议问题