# Open with other applications

  • If the developer wants toOther applications openThe list of their own development of the App, can refer to the following operation to achieve
  • Note: The Developer Tools version needs to be the latest Nightly, i.e. version >= 1.06.2407252
  • as well as Android SDK >= 1.3.26iOS SDK >= 1.3.36

# Operational steps

Open the WeChat Developer Tool and go toprojuect.miniapp.json And switch to json Pattern

2、Android Application: In Mini-Android Add the following configuration in


"mini-android":  {
    "sdkVersion": "1.3.20",
    "openMimeTyeps":[
      "application/pdf",//Type of file to open
      "image/*",//Type of file to open
      "More can be added as needed"
    ],
  }

iOS Application: Then in the mini-ios Add the following configuration in


"openMimeTyeps": [
      {
        "CFBundleTypeName":  "AnyName" 
        "LSHandlerRank":  "Default",
        "LSItemContentTypes": [
          "public.image"
        ],
        "CFBundleTypeRole":  "Viewer"
      }
    ],

Field Dxplaination:

  • CFBundleType Required, openMimeTypes is an array type, give an alias to each item of the array supported by this file
  • CFBundleTypeRole Required, identity, to identify themselves app Who can handle these documents, Editor、Viewer、Shell、None
  • LSHandlerRank Required, used to determine app Optional in file sharing app Order in the list, declaring the application priority Owner、Default、Alternate、None
  • LSItemContentTypes Required, Supported File Types UTI (Apple's own document type)
  • For more documents, please check Apple's official: https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW1

3, use wx.miniapp.registOpenURL Listen to open via file app The events of

  wx.miniapp.registOpenURL ((param) => {
    console.log('regsitOpenUrl',  param)
    // adopt isFile To identify whether it is a file or not, at this point the param.data.url The absolute path for the file in the phone file system
    if (param.data.isFile) {
        // do something
    }
})
  1. Use wx.miniapp.copyNativeFileToWx Copy files from the system into the wx File sandboxIncoming parameter nativeFilePath That is, the absolute path of the file in the phone's file system, which returns when successful tempFilePath
wx.miniapp.copyNativeFileToWx({
        nativeFilePath: param.data.url,
        success(res) {
          console.log('copyNativeFileToWx success', res)
        },
        fail(e) {
          console.log('copyNativeFileToWx fail', e)
        }
      })

Combined with the above steps, the complete example is as follows:

wx.miniapp.registOpenURL ((param) => {
    console.log('regsitOpenUrl',  param)
    if (param.data.isFile) {
      wx.miniapp.copyNativeFileToWx({
        nativeFilePath: param.data.url,
        success(res) {
          console.log('copyNativeFileToWx success', res)
        },
        fail(e) {
          console.log('copyNativeFileToWx fail', e)
        }
      })
    }
})