Shift2App
Home chevron_right Troubleshooting
build

Troubleshooting

Common issues and debugging tips

Common Issues

Solutions to frequent problems

shift2appjs is undefined

This means your code is running in a regular browser, not inside the Shift2App wrapper.

Solutions:

  • Test your app on a real device or emulator
  • Always check if shift2appjs exists before using it
  • Provide fallback behavior for browser testing
javascript
// Always check first
if (typeof shift2appjs !== "undefined") {
    shift2appjs.showToast("Native!");
} else {
    alert("Browser fallback");
}
Callback function not being called

Callback functions must be defined in the global scope.

javascript
// ❌ Wrong - function not accessible
function init() {
    function onResult(success) { }  // Local scope
    shift2appjs.authenticate("onResult");  // Won't work
}

// ✅ Correct - global function
window.onResult = function(success) {
    console.log(success);
};
shift2appjs.authenticate("onResult");
Ads not showing

Check the following:

  • AdMob is enabled in your dashboard
  • Valid AdMob App ID is configured
  • Ad Unit IDs are correct
  • Wait for ads to load: check isInterstitialAdReady()
  • Test with test ad IDs first
Push notifications not received

Troubleshooting steps:

  • Verify notifications are enabled in dashboard
  • Check google-services.json is configured
  • Ensure FCM token is registered: shift2appjs.registerFCMToken(userId)
  • Check your server is sending to the correct token
  • Verify notification permissions on device
Biometric authentication fails

Check the following:

  • Device has fingerprint/face hardware
  • User has enrolled biometrics in device settings
  • Check availability first: shift2appjs.isBiometricAvailable()

Debugging Tips

How to debug your integration

1. Use Console Logging

javascript
// Log all shift2appjs calls
const originalShowToast = shift2appjs.showToast;
shift2appjs.showToast = function(msg) {
    console.log("[shift2appjs.showToast]", msg);
    return originalShowToast.call(this, msg);
};

// Log return values
function debugCall(method, ...args) {
    console.log(`[shift2appjs.${method}]`, args);
    const result = shift2appjs[method](...args);
    console.log(`[shift2appjs.${method}] returned:`, result);
    return result;
}

2. Check Function Availability

javascript
// List all available functions
if (typeof shift2appjs !== "undefined") {
    const functions = Object.getOwnPropertyNames(shift2appjs)
        .filter(prop => typeof shift2appjs[prop] === "function");
    console.log("Available functions:", functions);
}

3. Android Studio Logcat

Use Android Studio's Logcat to see native logs. Filter by your app's package name.

Frequently Asked Questions

Can I use shift2appjs in an iframe?

Yes, shift2appjs is injected into all frames. However, for security, some functions may be restricted in iframes from different origins.

Does shift2appjs work offline?

Most shift2appjs functions work offline (storage, device info, UI). Network-dependent features like FCM registration require connectivity.

Can I add custom native functions?

The current version has a fixed set of functions. Contact support for custom development needs.

Is my data secure?

Data stored via shift2appjs.setItem() is saved in the app's private storage, not accessible to other apps. For sensitive data, use biometric authentication.

dashboard Dashboard menu_book Docs science Playground