stuyam / pressure

:point_down::boom: JavaScript library for handling Force Touch, 3D Touch, and Pointer Pressure.
https://pressurejs.com
MIT License
2.92k stars 97 forks source link

iPhone 7 - iOS 10.3.2 - touchforcechanged event never fired in standalone mode #66

Closed stephaneAG closed 7 years ago

stephaneAG commented 7 years ago

Related Stack Overflow question: https://stackoverflow.com/questions/45003908/iphone-7-ios-10-3-2-touchforcechange-event-never-fired

In shorts: as in the title: the 'touchforcechanged' event is never fired when a website saved to the springboard is launched in standalone mode :/

-> I first thought the issue was coming from your lib, but after re-implementing things myself without any polyfill, it seems it's iOS mobileSafari that bricks it .. or is it a feature ?

navigator.appVersion: 5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.0 Mobile/14F89 Safari/602.1


Device is a [?year] [iPhone] [7] Operating system is [iOS] [10.3.2] Browser is [MobileSafari] [Mobile/14F89 Safari/602.1]

stuyam commented 7 years ago

@stephaneAG thanks for reporting this. Sounds like an interesting bug. I will try to reproduce and see if there is anything more that we can find out about this issue. 😄

stuyam commented 7 years ago

So I figured it out with a little bit of testing. So there are two conflicting web views on iOS right now. There is UIWebView and WKWebView. UIWebView is the older version and is being phased out. I have seen people run into this before and the old UIWebView does not support 3D Touch events.

I did a test to see if when saving you add a website to your home screen it will open in a UIWebView and sure enough:

(When added to the home screen)

(When opened in safari)

This was the code I used to test the page that I took from a stackoverflow on how to determine which web view a site is running in with js. https://stackoverflow.com/questions/28795476/detect-if-page-is-loaded-inside-wkwebview-in-javascript

<!doctype html>
  <head>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <script>
      if (navigator.platform.substr(0,2) === 'iP'){
        //iOS (iPhone, iPod or iPad)
        var lte9 = /constructor/i.test(window.HTMLElement);
        var nav = window.navigator, ua = nav.userAgent, idb = !!window.indexedDB;
        if (ua.indexOf('Safari') !== -1 && ua.indexOf('Version') !== -1 && !nav.standalone){
          //Safari (WKWebView/Nitro since 6+)
          alert('Safari (WKWebView/Nitro since 6+)');
        } else if ((!idb && lte9) || !window.statusbar.visible) {
          //UIWebView
          alert('UIWebView');
        } else if ((window.webkit && window.webkit.messageHandlers) || !lte9 || idb){
          //WKWebView
          alert('WKWebView');
        }
      }
    </script>
  </head>
  <body>
  </body>
</html>

From what I understand Apple is phasing out the native looking pinned apps, only workaround I know would be to remove the <meta name="apple-mobile-web-app-capable" content="yes" /> line but then it would just open in Safari and not it's own "app".

Hope this helps! <3

stephaneAG commented 7 years ago

Hi there !

Sorry for the delay in my answer, things have been kinda busy these days :/ ;p

I wanted to thanks you VERY MUCH ( :D ) for your answer, I'm gonna dig this & see how this goes ..

btw: if it could help you in any way, I also stumbled upon the following: https://mislavjavor.github.io/2016-03-08/WKWebView-advanced-tutorial/

:)

=> Oh ! and also, if you were wondering if we can press images to save them to the camera roll in webapp mode -> it seems not :/ (.& this may come .. from what you pointed out ^^ )

Have a very nice day ++

SeedsDesign fruitfull ideas Regarding your request(s): # For an overview of how I may help you, see the following links Feel free to contact me See you soon ! CV https://mail.google.com/mail/u/0/?ui=2&ik=f69c66c90c&view=att&th=14f878eafb9ae057&attid=0.1&disp=safe&realattid=f_ie0ykb720&zw SeedsDesign 20 rue de l'Armorique 75015 PARIS Give me a call at 0681382722 <#UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_IDSafeHtmlFilter> [image: Facebook] http://www.facebook.com/ [image: Twitter] http://www.twitter.com/ ® SeedsDesign 2015

2017-07-11 21:46 GMT+02:00 Stuart Yamartino notifications@github.com:

So I figured it out with a little bit of testing. So there are two conflicting web views on iOS right now. There is UIWebView and WKWebView. UIWebView is the older version and is being phased out. I have seen people run into this before and the old UIWebView does not support 3D Touch events.

I did a test to see if when saving you add a website to your home screen it will open in a UIWebView and sure enough:

(When added to the home screen)

https://user-images.githubusercontent.com/1553779/28086916-a1827ea6-664e-11e7-80b4-09dbd944d4fa.PNG

(When opened in safari)

https://user-images.githubusercontent.com/1553779/28086949-c15c010c-664e-11e7-8a01-e3fae36aa377.png

This was the code I used to test the page that I took from a stackoverflow on how to determine which web view a site is running in with js. https://stackoverflow.com/questions/28795476/detect-if- page-is-loaded-inside-wkwebview-in-javascript

<!doctype html>

From what I understand Apple is phasing out the native looking pinned apps, only workaround I know would be to remove the <meta name="apple-mobile-web-app-capable" content="yes" /> line but then it would just open in Safari and not it's own "app".

Hope this helps! <3

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stuyam/pressure/issues/66#issuecomment-314551481, or mute the thread https://github.com/notifications/unsubscribe-auth/ABPOl7vv1hmutqjIz0csgHkc2iG2-gp0ks5sM9EWgaJpZM4OSXP7 .

stuyam commented 7 years ago

Yeah all of this things have to do with it being in the old UIWebView and not the new WKWebView unfortunately. Closing for now as it is out of my control 😢