Skip to main content
Use this API to determine feature availability before using version-specific functionality. This helps ensure graceful degradation on older Mini Program versions.

Parameters

PropertyTypeRequiredDescription
schemaStringYesThe feature schema to check (see syntax below)

Schema Syntax

The my.canIUse function accepts a dot-notation string to specify what feature to check:
Syntax: ${API}.${type}.${param}.${option}
PartDescription
APIName of the API to check
typeCheck type: object (parameter), return (return value), or callback
paramParameter or return property name
optionSpecific option or value to check

Return Value

TypeDescription
Booleantrue if the feature is supported, false otherwise

Code Examples

Check API Availability

// Check if an API exists
if (my.canIUse('getFileInfo')) {
  my.getFileInfo({
    filePath: 'path/to/file',
    success: (res) => {
      console.log(res.size);
    }
  });
} else {
  console.log('getFileInfo API not supported');
}

Check API Parameter Support

// Check if a specific parameter is supported
if (my.canIUse('getLocation.object.type')) {
  my.getLocation({
    type: 'gcj02',
    success: (res) => {
      console.log(res.latitude, res.longitude);
    }
  });
}

Check Return Value Support

// Check if a return property exists
if (my.canIUse('getSystemInfo.return.brand')) {
  my.getSystemInfo({
    success: (res) => {
      console.log('Device brand:', res.brand);
    }
  });
}

Check Component Attribute Support

// Check if a component attribute value is supported
if (my.canIUse('button.open-type.getAuthorize')) {
  // Can use button with open-type="getAuthorize"
}

Common Use Cases

Use my.canIUse to provide fallback behavior when features aren’t available:
function getLocation() {
  if (my.canIUse('getLocation.object.type')) {
    // Use enhanced location API
    my.getLocation({
      type: 'gcj02',
      success: handleLocation
    });
  } else {
    // Fallback to basic location
    my.getLocation({
      success: handleLocation
    });
  }
}
Conditionally render UI elements based on platform capabilities:
Page({
  data: {
    canAuthorize: false
  },
  onLoad() {
    this.setData({
      canAuthorize: my.canIUse('button.open-type.getAuthorize')
    });
  }
});
Always check feature availability before using APIs that may not be present in all Mini Program versions. This ensures your app works correctly across different platform versions.