def rm(udid, remote_path, bundle_id=None):
        """
        Removes a file or directory from the iOS device.

        Args:
            udid (str): The UDID of the iOS device.
            remote_path (str): The path of the file or directory on the iOS device.
            bundle_id (str, optional): The bundle ID of the app. If provided, the file or directory will be removed from the app's sandbox. Defaults to None.

        Examples:
            Remove a file from the DCIM directory::

                >>> TIDevice.rm("00008020-001270842E88002E", "/DCIM/photo.jpg")
                >>> TIDevice.rm("00008020-001270842E88002E", "/DCIM/photo.jpg", "com.apple.Photos")

            Remove a directory from the Documents directory of the Keynote app::

                >>> TIDevice.rm("00008020-001270842E88002E", "/Documents", "com.apple.Keynote")
        """

        def _check_status(status, path):
            if status == 0:
                print("removed", path)
            else:
                raise AirtestError(f"<{status.name} {status.value}> Failed to remove {path}")

        def _remove_folder(udid, folder_path, bundle_id):
            folder_path = folder_path.replace("\\", "/")
            for file_info in TIDevice.ls(udid, folder_path, bundle_id):
                if file_info['type'] == 'Directory':
                    _remove_folder(udid, os.path.join(folder_path, file_info['name']), bundle_id)
                else:
                    status = sync.remove(os.path.join(folder_path, file_info['name']))
                    _check_status(status, os.path.join(folder_path, file_info['name']))
            # remove the folder itself
            status = sync.remove(folder_path)
            _check_status(status, folder_path)

        if bundle_id:
            sync = BaseDevice(udid, Usbmux()).app_sync(bundle_id)
        else:
            sync = BaseDevice(udid, Usbmux()).sync

        if TIDevice.is_dir(udid, remote_path, bundle_id):
            if not remote_path.endswith("/"):
                remote_path += "/"
            _remove_folder(udid, remote_path, bundle_id)
        else:
            status = sync.remove(remote_path)
            _check_status(status, remote_path)

        Removes a file or directory from the iOS device.

        Args:
            udid (str): The UDID of the iOS device.
            remote_path (str): The path of the file or directory on the iOS device.
            bundle_id (str, optional): The bundle ID of the app. If provided, the file or directory will be removed from the app's sandbox. Defaults to None.

        Examples:
            Remove a file from the DCIM directory::

                >>> TIDevice.rm("00008020-001270842E88002E", "/DCIM/photo.jpg")
                >>> TIDevice.rm("00008020-001270842E88002E", "/DCIM/photo.jpg", "com.apple.Photos")

            Remove a directory from the Documents directory of the Keynote app::

                >>> TIDevice.rm("00008020-001270842E88002E", "/Documents", "com.apple.Keynote")
        
airtest/core/ios/ios.py