ICS file Download fails on iPhone Chrome with “Unknown File Type”

前端 未结 3 2106
无人及你
无人及你 2021-01-18 01:09

I\'ve got a php script that\'s auto-generating an ics file for a mobile web app.

Using Chrome on my Win7 desktop, the ics file downloads fine, and Outlook likes it.<

3条回答
  •  无人及你
    2021-01-18 01:31

    Use webcal://your_link.ics

    This should solve your problem. Here's a preview of how it'll appear

    Here's a jsbin demonstrating automatic selection of protocol basis the user agent.

    HTML:

    
    
    
      
      
      JS Bin
    
    
      Test webcal://
      

    Test https://

    Auto (check JS)

    Javascript:

    // Source: https://stackoverflow.com/a/9039885/3577736
    function is_iOS() {
      return [
        'iPad Simulator',
        'iPhone Simulator',
        'iPod Simulator',
        'iPad',
        'iPhone',
        'iPod'
      ].includes(navigator.platform)
      // iPad on iOS 13 detection
      || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
    }
    
    if(is_iOS()) {
        document.getElementById('auto').href = document.getElementById('auto').href.replace(/https?:/, 'webcal:');
    }
    
    // Debugging
    document.getElementById('ua').value =  navigator.userAgent;
    

    CSS:

    textarea {
      width: 100%
    }
    

提交回复
热议问题