### Initial Project Setup Bash Script
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Shell script to set up the project environment, including installing Homebrew, CocoaPods, Node.js dependencies, preparing the iOS platform, and opening the Xcode workspace. Ensure Homebrew is installed and configured before running.
```bash
# Install Homebrew (if not installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Configure Homebrew environment
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
# Install CocoaPods via Homebrew
brew install cocoapods
# Install Node.js dependencies for Cordova
cd MainCordovaApplication
npm install
# Prepare iOS platform files
npm run cordova prepare ios
# Return to project root and install pods
cd ..
pod install
# Open workspace in Xcode
open MiniappSDKDemoApplication.xcworkspace
```
--------------------------------
### Automated Cordova Preparation in Xcode Build Phase
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Instructions to configure Xcode's 'Run Script' build phase to automatically prepare the Cordova iOS platform. This ensures the Cordova environment is up-to-date before building the native application. It shows examples using a direct path, global Cordova installation, and npx.
```bash
# In Xcode, configure automatic Cordova preparation:
# 1. Select CordovaDemoApp project in navigator (cmd + 1)
# 2. Select CordovaDemoApp target
# 3. Open Build Phases tab
# 4. Expand "Run Script" phase
# 5. Add the following line:
path/to/installed/cordova prepare ios
# Example with global Cordova:
/usr/local/bin/cordova prepare ios
# Example with npx:
cd MainCordovaApplication && npx cordova prepare ios
```
--------------------------------
### Installing and Launching Debug Miniapp Swift
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Swift function to handle the installation and launching of a debug miniapp from a local zip file. It copies the file to the documents directory, installs it using the SDK, and then launches it, providing error handling for each step.
```swift
import MiniappSDK_demo
// Install miniapp from local zip file
func handleDroppedFile(_ fileURL: URL) {
guard fileURL.startAccessingSecurityScopedResource() else { return }
defer { fileURL.stopAccessingSecurityScopedResource() }
do {
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let destinationURL = documentsURL.appendingPathComponent(fileURL.lastPathComponent)
try? FileManager.default.removeItem(at: destinationURL)
try FileManager.default.copyItem(at: fileURL, to: destinationURL)
guard let sdk = MiniappsSDK.shared else {
throw NSError(domain: "Installation error", code: -1, userInfo: [NSLocalizedDescriptionKey: "SDK is uninitialized"])
}
try sdk.installDebugMiniapp(filePath: destinationURL.path)
// Launch the installed miniapp
sdk.launchMiniapp(
appId: MiniappsSDK.debugMiniappID,
addressID: MiniappsSDK.debugMiniappID,
launchType: .present(over: self, animated: true)
)
} catch {
print("Installation error: \(error.localizedDescription)")
}
}
```
--------------------------------
### Install iOS Project Dependencies
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
Installs the necessary dependencies for the iOS project using Cocoapods. This command should be executed once before the first run of the application.
```bash
pod install
```
--------------------------------
### Install Cordova Packages
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
Installs Cordova and its required packages within the 'MainCordovaApplication' directory using npm or yarn. This command prepares the project for building.
```bash
cd MainCordovaApplication
npm install
```
```bash
cd MainCordovaApplication
yarn install
```
--------------------------------
### Initiating Invoice Payment with Cordova Plugin (JavaScript)
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Shows how to start the invoice payment flow using the Cordova Condo plugin. It provides both callback-based and Promise-based APIs for handling the asynchronous payment process. Includes example usage within a button click handler, requiring 'invoiceID' input and functions 'showSuccessMessage' and 'showErrorMessage'.
```javascript
// Callback-based API
function initiatePayment(invoiceID) {
cordova.plugins.condo.startInvoicePayment(
invoiceID,
function(response) {
console.log("Payment completed:", JSON.stringify(response));
// Handle successful payment
showSuccessMessage();
},
function(error) {
console.error("Payment failed:", error);
// Handle payment error
showErrorMessage(error);
}
);
}
// Promise-based API
async function initiatePaymentAsync(invoiceID) {
try {
const response = await cordova.plugins.condo.withPromises.startInvoicePayment(invoiceID);
console.log("Payment completed:", JSON.stringify(response));
showSuccessMessage();
} catch (error) {
console.error("Payment failed:", error);
showErrorMessage(error);
}
}
// Example: Button handler
document.getElementById('payButton').addEventListener('click', function() {
const invoiceID = document.getElementById('invoiceID').value;
initiatePaymentAsync(invoiceID);
});
```
--------------------------------
### Testing on Simulator and Device
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Guides for debugging the application using Safari Web Inspector on a simulator and instructions for testing on a production device.
```APIDOC
## Testing
### Safari Web Inspector (Simulator)
#### Description
This method allows you to debug your application running in the iOS simulator using Safari's Web Inspector, providing full debugging capabilities.
#### Steps
1. Build and run the app in the Xcode simulator (Cmd + R).
2. On macOS, open Safari > Preferences > Advanced and enable "Show Develop menu in menu bar".
3. In the Safari menu bar, navigate to Develop > [Your Simulator Name] > [Your Miniapp WebView].
#### Capabilities
- Console for JavaScript logging
- Elements inspector for DOM
- Network monitor
- Debugger with breakpoints
### Production Testing (Real Device)
#### Description
Instructions for building an archive of your miniapp and preparing it for testing on a production device.
#### Steps
1. Build the miniapp archive:
```bash
cd MainCordovaApplication/platforms/ios
zip -r www.zip www/
```
2. Upload the `www.zip` file to iCloud Drive.
3. Install the Doma app from the App Store on your device.
```
--------------------------------
### Prepare Cordova iOS Platform
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
Prepares the iOS platform for the Cordova application after code modifications. This command can be run using npm, yarn, or a globally installed Cordova CLI.
```bash
npm run cordova prepare ios
```
```bash
yarn cordova prepare ios
```
```bash
cordova prepare ios
```
--------------------------------
### JavaScript: Get Environment Information with Condo Plugin
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
Retrieve information about the current running environment using the cordova.plugins.condo.hostApplication object. This includes checking if it's a demo environment, getting the base URL, installation ID, device ID, and the application's locale.
```javascript
console.log(cordova.plugins.condo.hostApplication.isDemoEnvironment());
```
```javascript
console.log(cordova.plugins.condo.hostApplication.baseURL());
```
```javascript
console.log(cordova.plugins.condo.hostApplication.installationID());
```
```javascript
console.log(cordova.plugins.condo.hostApplication.deviceID());
```
```javascript
console.log(cordova.plugins.condo.hostApplication.locale());
```
--------------------------------
### Install Cocoapods
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
Installs Cocoapods, a dependency manager for Swift and Objective-C Cocoa projects, using Homebrew. This is crucial for managing iOS project dependencies.
```bash
brew install cocoapods
```
--------------------------------
### Install Homebrew
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
Installs Homebrew, a package manager for macOS, which is a prerequisite for installing other development tools like Cocoapods and Node.js.
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> ~/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
```
--------------------------------
### Access Host Application Environment Information
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Shows how to retrieve various environment details from the host application using the cordova.plugins.condo.hostApplication API. This includes checking if the app is running in a demo environment, getting the base URL, installation ID, device ID, and locale.
```javascript
document.addEventListener('deviceready', function() {
// Check if running in demo environment
const isDemo = cordova.plugins.condo.hostApplication.isDemoEnvironment();
console.log("Is demo environment:", isDemo);
// Get base URL of current server
const baseURL = cordova.plugins.condo.hostApplication.baseURL();
console.log("Base URL:", baseURL); // e.g., "https://condo.d.doma.ai"
// Get installation ID (unique per app installation)
const installationID = cordova.plugins.condo.hostApplication.installationID();
console.log("Installation ID:", installationID);
// Get device ID (unique per device)
const deviceID = cordova.plugins.condo.hostApplication.deviceID();
console.log("Device ID:", deviceID);
// Get application locale
const locale = cordova.plugins.condo.hostApplication.locale();
console.log("Locale:", locale); // e.g., "ru-RU", "en-US"
// Use locale for internationalization
loadTranslations(locale);
}, false);
```
--------------------------------
### Safari Web Inspector Debugging Setup (macOS)
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Provides command-line instructions for setting up Safari's Web Inspector to debug a Cordova application running on an iOS simulator. It involves building and running the app in Xcode, enabling developer options in Safari preferences, and then accessing the simulator's WebView through the Safari Develop menu.
```bash
# 1. Build and run app in Xcode simulator (cmd + R)
# 2. On macOS:
# - Open Safari
# - Safari > Preferences > Advanced
# - Enable "Show Develop menu in menu bar"
# 3. In Safari menu bar:
# - Develop > [Your Simulator Name] > [Your Miniapp WebView]
#
# 4. Web Inspector opens with full debugging capabilities:
# - Console for JavaScript logging
# - Elements inspector for DOM
# - Network monitor
# - Debugger with breakpoints
```
--------------------------------
### Get Launch Context with Cordova Plugin
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Retrieves the launch context of the miniapp using the cordova-plugin-condo. The context provides information about how the miniapp was initiated, such as from a notification or deep link. This function requires the 'deviceready' event to be fired.
```javascript
document.addEventListener('deviceready', function() {
cordova.plugins.condo.getLaunchContext(
function(contextString) {
console.log("Launch context:", contextString);
// Context contains information about how miniapp was launched
// (e.g., from notification, deep link, etc.)
},
function(error) {
console.error("Failed to get launch context:", error);
}
);
}, false);
```
--------------------------------
### Listen for Navigation State Changes
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Demonstrates how to subscribe to 'condoPopstate' events to detect changes in the navigation state. It includes logic to update the UI based on the new state and provides example functions for navigating to different screens like 'details', 'list', and 'main'.
```javascript
// Listen for navigation state changes
addEventListener("condoPopstate", function(event) {
console.log("Navigation state changed:", JSON.stringify(event.state));
// Update UI based on state
if (event.state && event.state.screen) {
renderScreen(event.state.screen, event.state);
}
});
// Example: Single-page navigation implementation
function navigateToDetails(itemId) {
cordova.plugins.condo.history.pushState(
{ screen: "details", itemId: itemId },
"Item Details"
);
renderDetailsScreen(itemId);
}
function renderScreen(screenName, state) {
switch (screenName) {
case "details":
renderDetailsScreen(state.itemId);
break;
case "list":
renderListScreen();
break;
default:
renderMainScreen();
}
}
```
--------------------------------
### Handle System Back Button Events
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Provides an example of how to listen for and handle the system's back button press using the 'backbutton' event listener. It includes custom logic to navigate within the app or close the application based on the current screen state.
```javascript
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
// Handle the system back button press
console.log("Back button pressed");
// Custom navigation logic
if (currentScreen === "details") {
// Go back to list
cordova.plugins.condo.history.back();
} else if (currentScreen === "main") {
// Close application
cordova.plugins.condo.closeApplication();
}
}
```
--------------------------------
### Configure Swift Collections Module with CMake
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/MiniappSDK.xcframework/ios-arm64/MiniappSDK_demo.framework/Frameworks/LocalExtensions.framework/CMakeLists.txt
This CMake script configures the build process for Swift Collections. It conditionally sets the module name and adds libraries and sources based on the COLLECTIONS_SINGLE_MODULE flag. It also handles target properties and installation.
```cmake
if(COLLECTIONS_SINGLE_MODULE)
set(module_name ${COLLECTIONS_MODULE_NAME})
else()
set(module_name InternalCollectionsUtilities)
add_library(InternalCollectionsUtilities
${COLLECTIONS_UTILITIES_SOURCES})
set_target_properties(InternalCollectionsUtilities PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
_install_target(InternalCollectionsUtilities)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS InternalCollectionsUtilities)
endif()
target_sources (${module_name} PRIVATE
"autogenerated/Debugging.swift"
"autogenerated/Descriptions.swift"
"autogenerated/RandomAccessCollection+Offsets.swift"
"autogenerated/Specialize.swift"
"autogenerated/UnsafeBufferPointer+Extras.swift"
"autogenerated/UnsafeMutableBufferPointer+Extras.swift"
"Compatibility/autogenerated/UnsafeMutableBufferPointer+SE-0370.swift"
"Compatibility/autogenerated/UnsafeMutablePointer+SE-0370.swift"
"Compatibility/autogenerated/UnsafeRawPointer extensions.swift"
"IntegerTricks/autogenerated/FixedWidthInteger+roundUpToPowerOfTwo.swift"
"IntegerTricks/autogenerated/Integer rank.swift"
"IntegerTricks/autogenerated/UInt+first and last set bit.swift"
"IntegerTricks/autogenerated/UInt+reversed.swift"
"UnsafeBitSet/autogenerated/_UnsafeBitSet+Index.swift"
"UnsafeBitSet/autogenerated/_UnsafeBitSet+_Word.swift"
"UnsafeBitSet/autogenerated/_UnsafeBitSet.swift"
"_SortedCollection.swift"
"_UniqueCollection.swift"
)
```
--------------------------------
### Close Miniapp with Cordova Plugin
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Closes the currently active miniapp using the cordova-plugin-condo. Includes callbacks for success and failure. An example demonstrates binding this function to a button click.
```javascript
function closeApplication() {
cordova.plugins.condo.closeApplication(
function(response) {
console.log("Application closed");
},
function(error) {
console.error("Close failed:", error);
}
);
}
// Example: Bind to close button
document.getElementById("CloseButton").addEventListener("click", closeApplication);
```
--------------------------------
### Share Local Document using Web API
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This example demonstrates how to share a local document (e.g., a PDF) using the Navigator.share API. It fetches the file as a blob, creates a File object, and then initiates the share action. On iOS, this must be triggered by user interaction.
```html
```
--------------------------------
### Get Current Resident/Address with Cordova Plugin
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Retrieves the current resident and address information using the cordova-plugin-condo. This data can be used to contextualize the miniapp's behavior. It includes success and error callbacks.
```javascript
cordova.plugins.condo.getCurrentResident(
function(response) {
console.log("Current resident/address:", JSON.stringify(response));
// Response contains resident and property information
// Use this to contextualize miniapp behavior
},
function(error) {
console.error("Failed to get resident:", error);
}
);
```
--------------------------------
### Enabling Debug Logging with Cordova Plugin (JavaScript)
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
This snippet demonstrates how to enable verbose debug logging for the Cordova Condo plugin. It must be called after the 'deviceready' event fires. Once enabled, subsequent plugin operations will produce more detailed logs in the console. Includes an example of fetching resident data.
```javascript
document.addEventListener('deviceready', function() {
// Enable debug logging
cordova.plugins.condo.debug.setDebugLoggingEnabled(true);
console.log("Debug logging enabled");
// Perform operations - logs will be more verbose
cordova.plugins.condo.getCurrentResident(
function(response) {
console.log("Resident data:", response);
},
function(error) {
console.error("Error:", error);
}
);
}, false);
```
--------------------------------
### Get Launch Context (JavaScript)
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This JavaScript function retrieves the application's launch context, which might include data passed from a notification or other launch parameters. It utilizes success and error callback functions to handle the context string or any errors encountered.
```javascript
cordova.plugins.condo.getLaunchContext(function(b2cAppContextString) {}, function(error) {});
```
--------------------------------
### Close Application (JavaScript)
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This JavaScript function is used to close the current application. It accepts success and error callback functions, although the example shows empty callbacks, indicating that no specific actions are taken upon success or failure in this implementation.
```javascript
cordova.plugins.condo.closeApplication(function(response) {}, function(error) {});
```
--------------------------------
### Get Current Resident/Address (JavaScript)
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This JavaScript function retrieves information about the current resident or address associated with the application session. It takes success and error callback functions as arguments to handle the retrieved data or any errors that occur during the process.
```javascript
cordova.plugins.condo.getCurrentResident(function(response) {
console.log("current resident\address => ", JSON.stringify(response));
}, function(error) {
console.log(error);
});
```
--------------------------------
### SDK Initialization and Address Setting Swift
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Swift code demonstrating the initialization of the MiniappsSDK with a client ID secret and environment. It then sets the partner client address, handling success or failure scenarios for both SDK login and address setting.
```swift
import MiniappSDK_demo
// Initialize SDK with authentication
MiniappsSDK.login(clientIdSecret: "demo", environment: .devevelopment) { result in
switch result {
case .success(let sdk):
// Set address for miniapp context
let addressDescriptor = MiniappsSDK.PartnerClientAddress(
address: "Ростовская обл, г Ростов-на-Дону, ул Кудрявая, д 6",
unitName: "88",
unitType: .flat
)
sdk.setAddress(addressList: [addressDescriptor]) { addressResults in
guard let firstAddressResult = addressResults.first?.value else { return }
switch firstAddressResult {
case .success(let addressID):
print("Address set successfully: \(addressID)")
case .failure(let error):
print("Failed to set address: \(error.localizedDescription)")
}
}
case .failure(let error):
print("SDK initialization failed: \(error.localizedDescription)")
}
}
```
--------------------------------
### Production Testing Build Archive (iOS)
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
These bash commands outline the process for creating a production build archive of a Cordova miniapp for iOS. It involves navigating to the platform-specific directory, zipping the 'www' folder which contains the application's web assets, and preparing it for upload, likely to cloud storage like iCloud Drive.
```bash
# 1. Build miniapp archive
cd MainCordovaApplication/platforms/ios
zip -r www.zip www/
# 2. Upload to iCloud Drive
# 3. Install Doma app from App Store
```
--------------------------------
### Adding and Testing a Cordova Plugin (Bash/JavaScript)
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
This snippet demonstrates how to add a new Cordova plugin (e.g., cordova-plugin-device) to a Cordova project using npm, followed by manual steps for native code integration in Xcode. It also shows how to test the plugin's functionality in JavaScript by accessing device information.
```bash
# Example: Adding cordova-plugin-device
cd MainCordovaApplication
# Install plugin via npm
npm run cordova plugin add cordova-plugin-device
# Add native code to Xcode project:
# 1. Open MainCordovaApplication/platforms/ios/Plugins directory
# 2. Drag plugin directory into Xcode project's Plugins group
# 3. Keep only src/ios directory, remove references to other files
# 4. Open MainCordovaApplication/platforms/ios/HelloCordova/config.xml
# 5. Copy new and entries
# 6. Paste into main project's Cordova/config.xml
```
```javascript
# Test the plugin
# In www/js/index.js:
document.addEventListener('deviceready', function() {
console.log('Device model:', device.model);
console.log('Device platform:', device.platform);
console.log('Device version:', device.version);
}, false);
```
```bash
# Rebuild and run
npm run cordova prepare ios
# Then run in Xcode
```
--------------------------------
### Run Cordova Prepare iOS Script in Xcode
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
Configures Xcode to automatically run the 'cordova prepare ios' command during project builds. This optimizes the development workflow by avoiding manual terminal commands after code changes.
```bash
path/to/installed/cordova prepare ios
```
--------------------------------
### Importing Images
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Demonstrates how to use HTML input elements to capture single or multiple images using the device camera or image picker. Includes JavaScript for handling file selection and displaying images.
```APIDOC
## Importing Images
### Description
This section details how to import images from the device's camera or gallery using HTML input elements. It covers capturing single photos, selecting single images, and selecting multiple images. JavaScript code is provided to handle file selection events and process the selected image data.
### Usage
#### Single Photo Capture
```html
```
#### Single Image Selection
```html
```
#### Multiple Image Selection
```html
```
### Event Handling (Multiple Images)
#### JavaScript
```javascript
document.getElementById('multipleImagesInput').addEventListener('change', function(event) {
const files = event.target.files;
console.log(`Selected ${files.length} images`);
for (let i = 0; i < files.length; i++) {
const file = files[i];
const reader = new FileReader();
reader.onload = function(e) {
console.log(`Loaded image ${i + 1}: ${file.name}, size: ${file.size} bytes`);
// Process image data in e.target.result
displayImage(e.target.result);
};
reader.readAsDataURL(file);
}
});
function displayImage(dataUrl) {
const img = document.createElement('img');
img.src = dataUrl;
img.style.maxWidth = '200px';
document.getElementById('imageContainer').appendChild(img);
}
```
```
--------------------------------
### Miniapp Configuration JSON
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Configuration file for a Condo Miniapp, specifying its version, presentation style, mobile permissions, and minimum supported host application version for iOS. This JSON defines the miniapp's behavior and requirements.
```json
{
"version": "0.1",
"presentationStyle": "native",
"mobile_permissions": [
"record_audio",
"camera",
"audio_settings",
"bluetooth_central_background",
"bluetooth_peripheral_background",
"bluetooth_beacon_background"
],
"hostApplication": {
"iOS": {
"minimumSupportedVersion": "1.1.38"
}
}
}
```
--------------------------------
### Launch Miniapp with Swift
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Launches a miniapp using the MiniappsSDK. Requires a valid appId and addressId. The launch type determines how the miniapp is presented. Error handling is included for launch failures.
```swift
import MiniappSDK_demo
func launchMiniapp() {
guard let miniappSDK = MiniappsSDK.shared else { return }
miniappSDK.launchMiniapp(
appId: MiniappsSDK.debugMiniappID,
addressID: "your-address-id",
launchType: .present(over: self, animated: true)
) { error in
if let error = error {
print("Launch error: (error.localizedDescription)")
} else {
print("Miniapp launched successfully")
}
}
}
```
--------------------------------
### Configure Environment-Based API Endpoints
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Illustrates how to dynamically determine the API endpoint based on whether the application is running in a demo or production environment. It also shows how to initialize the application with the correct API endpoint, locale, and device ID.
```javascript
function getAPIEndpoint() {
const baseURL = cordova.plugins.condo.hostApplication.baseURL();
const isDemo = cordova.plugins.condo.hostApplication.isDemoEnvironment();
if (isDemo) {
return `${baseURL}/api/v1/demo`;
} else {
return `${baseURL}/api/v1/production`;
}
}
function initializeApp() {
const apiEndpoint = getAPIEndpoint();
const locale = cordova.plugins.condo.hostApplication.locale();
const deviceID = cordova.plugins.condo.hostApplication.deviceID();
console.log(`Initializing with endpoint: ${apiEndpoint}, locale: ${locale}, device: ${deviceID}`);
// Configure API client
configureAPIClient({
baseURL: apiEndpoint,
locale: locale,
deviceID: deviceID
});
}
document.addEventListener('deviceready', initializeApp, false);
```
--------------------------------
### Invoice Payment Flow
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Details on how to initiate the invoice payment process using both callback-based and promise-based APIs provided by the cordova.plugins.condo library.
```APIDOC
## Invoice Payment
### Starting Invoice Payment Flow
#### Description
This API allows you to initiate the invoice payment flow within the application. It supports both callback-based and promise-based implementations for handling payment success and failure.
#### Callback-based API
```javascript
function initiatePayment(invoiceID) {
cordova.plugins.condo.startInvoicePayment(
invoiceID,
function(response) {
console.log("Payment completed:", JSON.stringify(response));
// Handle successful payment
showSuccessMessage();
},
function(error) {
console.error("Payment failed:", error);
// Handle payment error
showErrorMessage(error);
}
);
}
```
#### Promise-based API
```javascript
async function initiatePaymentAsync(invoiceID) {
try {
const response = await cordova.plugins.condo.withPromises.startInvoicePayment(invoiceID);
console.log("Payment completed:", JSON.stringify(response));
showSuccessMessage();
} catch (error) {
console.error("Payment failed:", error);
showErrorMessage(error);
}
}
```
#### Example Usage (Button Handler)
```javascript
document.getElementById('payButton').addEventListener('click', function() {
const invoiceID = document.getElementById('invoiceID').value;
initiatePaymentAsync(invoiceID);
});
```
```
--------------------------------
### Debugging Tools
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Instructions on enabling debug logging and registering events for local notification representation to aid in debugging the application.
```APIDOC
## Debugging
### Enabling Debug Logging
#### Description
This feature allows you to enable verbose logging for debugging purposes. Logs will become more detailed when debug logging is active.
#### JavaScript
```javascript
document.addEventListener('deviceready', function() {
// Enable debug logging
cordova.plugins.condo.debug.setDebugLoggingEnabled(true);
console.log("Debug logging enabled");
// Perform operations - logs will be more verbose
cordova.plugins.condo.getCurrentResident(
function(response) {
console.log("Resident data:", response);
},
function(error) {
console.error("Error:", error);
}
);
}, false);
```
### Local Notification Debug Registration
#### Description
Register specific event names to trigger local notifications, which can be useful for debugging event-driven functionalities.
#### JavaScript
```javascript
// Register event name for local notification representation
cordova.plugins.condo.debug.setEventNameRegisteredForLocalNotificationRepresentation(
'messageReceived',
true
);
// Now when 'messageReceived' events occur, they can trigger local notifications
document.addEventListener('messageReceived', function(event) {
console.log("Message received event:", event);
});
```
```
--------------------------------
### Importing Videos
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Provides HTML and JavaScript for importing videos, allowing users to record a video using the camera or select existing videos from their device. Supports single and multiple video selections.
```APIDOC
## Importing Videos
### Description
This section outlines the process of importing videos using HTML input elements. It covers recording videos directly with the camera and selecting existing video files from the device, including options for single and multiple video selections. JavaScript is included to handle the selected video files and display them.
### Usage
#### Video Recording
```html
```
#### Single Video Selection
```html
```
#### Multiple Video Selection
```html
```
### Event Handling (Single Video)
#### JavaScript
```javascript
document.getElementById('singleVideoInput').addEventListener('change', function(event) {
const file = event.target.files[0];
if (!file) return;
console.log(`Selected video: ${file.name}, size: ${file.size} bytes, type: ${file.type}`);
const videoURL = URL.createObjectURL(file);
const videoElement = document.createElement('video');
videoElement.src = videoURL;
videoElement.controls = true;
videoElement.style.maxWidth = '100%';
document.getElementById('videoContainer').appendChild(videoElement);
});
```
```
--------------------------------
### Importing Videos with HTML and JavaScript
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Provides HTML input elements for selecting or recording videos. The accompanying JavaScript handles the selection of a single video, logs its details, creates a URL for the video, and appends a video player element to the DOM. Requires a 'videoContainer' element in the HTML.
```html
```
```javascript
document.getElementById('singleVideoInput').addEventListener('change', function(event) {
const file = event.target.files[0];
if (!file) return;
console.log(`Selected video: ${file.name}, size: ${file.size} bytes, type: ${file.type}`);
const videoURL = URL.createObjectURL(file);
const videoElement = document.createElement('video');
videoElement.src = videoURL;
videoElement.controls = true;
videoElement.style.maxWidth = '100%';
document.getElementById('videoContainer').appendChild(videoElement);
});
```
--------------------------------
### Importing Images with HTML and JavaScript
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Demonstrates how to use HTML input elements to allow users to select single or multiple images from their device. It includes JavaScript to handle the file selection, read image data using FileReader, and display the images. Requires an 'imageContainer' element in the HTML for displaying images.
```html
```
```javascript
document.getElementById('multipleImagesInput').addEventListener('change', function(event) {
const files = event.target.files;
console.log(`Selected ${files.length} images`);
for (let i = 0; i < files.length; i++) {
const file = files[i];
const reader = new FileReader();
reader.onload = function(e) {
console.log(`Loaded image ${i + 1}: ${file.name}, size: ${file.size} bytes`);
// Process image data in e.target.result
displayImage(e.target.result);
};
reader.readAsDataURL(file);
}
});
function displayImage(dataUrl) {
const img = document.createElement('img');
img.src = dataUrl;
img.style.maxWidth = '200px';
document.getElementById('imageContainer').appendChild(img);
}
```
--------------------------------
### Manage Navigation Stack with Condo History API
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Demonstrates how to manipulate the navigation stack using pushState, replaceState, back, and go methods provided by the cordova.plugins.condo.history API. This allows for programmatic control over the application's navigation flow and the behavior of back navigation.
```javascript
document.addEventListener('deviceready', function() {
// Push new state to navigation stack (creates back button)
cordova.plugins.condo.history.pushState(
{ screen: "details", itemId: 123 },
"Item Details"
);
// Replace current state without adding to stack
cordova.plugins.condo.history.replaceState(
{ screen: "details", itemId: 123 },
"Updated Title"
);
// Navigate back one step
cordova.plugins.condo.history.back();
// Navigate back multiple steps (always negative)
cordova.plugins.condo.history.go(-2);
}, false);
```
--------------------------------
### JavaScript: Control Navigation Stack with Condo Plugin
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
Manage the miniapp navigation stack using methods like pushState, replaceState, back, and go provided by the cordova.plugins.condo.history object. These methods allow programmatic control over the navigation flow and titles displayed in the system navigation bar. Ensure to handle the Cordova backbutton event for native back button presses.
```javascript
cordova.plugins.condo.history.pushState({"StateKey": "StateValue"}, "Title for navigation bar");
```
```javascript
cordova.plugins.condo.history.replaceState({"StateKey": "StateValue"}, "Title for navigation bar");
```
```javascript
cordova.plugins.condo.history.back();
```
```javascript
cordova.plugins.condo.history.go(-1);
```
```javascript
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
// Handle the back button
}
```
```javascript
addEventListener("condoPopstate", (event) => {console.log("condoPopstate => ", JSON.stringify(event.state));});
```
--------------------------------
### Authorize Server with Cordova Plugin
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Requests server authorization using the miniapp server OIDC endpoint via the cordova-plugin-condo. This function should be called after the 'deviceready' event. It logs success or failure and reloads the window upon successful authorization.
```javascript
document.addEventListener('deviceready', function() {
// Request authorization via miniapp server OIDC endpoint
cordova.plugins.condo.requestServerAuthorizationByUrl(
'https://miniapp.d.doma.ai/oidc/auth',
{},
function(response) {
console.log('Authorization successful:', JSON.stringify(response));
// Reload to apply authenticated session
window.location.reload();
},
function(error) {
console.error('Authorization failed:', error);
}
);
}, false);
```
--------------------------------
### Add Cordova Device Plugin (npm/yarn)
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This command adds the 'cordova-plugin-device' plugin to your Cordova project. It's a common step for integrating device-specific features. The command can be executed using either npm or yarn as your package manager.
```bash
cd MainCordovaApplication
npm run cordova plugin add cordova-plugin-device
# or `yarn cordova plugin add cordova-plugin-device` if you are using Yarn as your package manager
```
--------------------------------
### Share Local Files Using Web Share API
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Demonstrates how to share a local file using the `navigator.share` API. This function fetches a local file as a blob, converts it into a `File` object, and then initiates the sharing process. It requires user interaction to be called.
```javascript
function shareSomeDocument() {
fetch('some/path/to/local/document.pdf')
.then(function(response) {
return response.blob();
})
.then(function(blob) {
const file = new File([blob], "document.pdf", { type: blob.type });
const filesArray = [file];
navigator.share({
files: filesArray
}).then(function() {
console.log("File shared successfully");
}).catch(function(error) {
console.error("Share failed:", error);
});
})
.catch(function(error) {
console.error("Failed to load file:", error);
});
}
// IMPORTANT: Must be called in response to user interaction
document.getElementById('shareButton').addEventListener('click', shareSomeDocument);
```
--------------------------------
### Request Server Authorization (JavaScript)
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This JavaScript function initiates an authorization process by sending a request to a specified server URL. It accepts the authorization URL, an optional parameter for future use, and callback functions for success and error handling. The success callback typically reloads the window upon successful authorization.
```javascript
cordova.plugins.condo.requestServerAuthorizationByUrl('https://miniapp.d.doma.ai/oidc/auth', {}, function(response) {
console.log('recive authorication result => ', JSON.stringify(response));
window.location.reload();
}, function(error) {
console.log(error);
});
```
--------------------------------
### Check Authentication Status with Cordova Plugin and Fetch API
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Checks the user's authentication status by querying a GraphQL API. If authenticated, it logs the user's details. If not, it initiates the server authorization flow using the cordova-plugin-condo. This utilizes the Fetch API for network requests.
```javascript
// Check if user is authenticated by querying API
const data = {
"variables": {},
"query": "{\n authenticatedUser {\n id\n name\n email\n isAdmin\n __typename\n }\n}"
};
const options = {
method: 'POST',
body: JSON.stringify(data),
credentials: "include",
headers: {
'Content-Type': 'application/json'
}
};
fetch('https://miniapp.d.doma.ai/admin/api', options)
.then(res => res.json())
.then((res) => {
if (res.data.authenticatedUser) {
console.log('User authenticated:', JSON.stringify(res.data.authenticatedUser));
// Proceed with authenticated operations
} else {
console.log('User not authenticated');
// Trigger authorization flow
cordova.plugins.condo.requestServerAuthorizationByUrl(
'https://miniapp.d.doma.ai/oidc/auth',
{},
function(response) {
window.location.reload();
},
function(error) {
console.error(error);
}
);
}
})
.catch(err => console.error(err));
```
--------------------------------
### Content Security Policy Configuration (HTML)
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
This HTML meta tag configures the Content Security Policy (CSP) for the Cordova application. It specifies which domains and sources are allowed to load resources, enhancing security by mitigating cross-site scripting (XSS) and other injection attacks.
```html
```
--------------------------------
### Import Image using HTML Input
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
These HTML input elements allow users to import images into the application. Different attributes control whether the camera is opened, if single or multiple images can be selected.
```html
```
```html
```
```html
```
--------------------------------
### Enable/Disable Mini-App Debugging (URL Scheme)
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
These URL schemes are used to control the debugging capabilities of mini-applications within the Doma app. 'enable' turns on the debugging features, providing access to the JS console and other diagnostic tools, while 'disable' turns them off. These are essential for development and testing phases.
```url
ai.doma.client.service://miniapps/local/enable
```
```url
ai.doma.client.service://miniapps/local/disable
```
--------------------------------
### Import Video using HTML Input
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This HTML input element allows users to import videos into the application. Similar to image import, the 'accept' attribute is used to specify the file type.
```html
```
--------------------------------
### Enable Background Bluetooth Peripheral - Cordova JSON Config
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This JSON configuration enables the background Bluetooth peripheral functionality for the cordova-plugin-ble-peripheral. It requires adding the 'bluetooth_peripheral_background' flag to the 'mobile_permissions' array in `www/native_config.json`. This allows the application to act as a Bluetooth peripheral in the background.
```json
{
"presentationStyle": "native",
"mobile_permissions": ["bluetooth_peripheral_background"],
"hostApplication": {
"iOS": {
"minimumSupportedVersion": "1.1.22"
}
}
}
```
--------------------------------
### Enable Background Beacon Scanning - Cordova JSON Config
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This JSON configuration enables the background beacon scanning functionality for the com.unarin.cordova.beacon plugin. It requires adding the 'bluetooth_beacon_background' flag to the 'mobile_permissions' array in `www/native_config.json`. This allows the application to detect beacons while running in the background.
```json
{
"presentationStyle": "native",
"mobile_permissions": ["bluetooth_beacon_background"],
"hostApplication": {
"iOS": {
"minimumSupportedVersion": "1.1.22"
}
}
}
```
--------------------------------
### Local Notification Debug Registration (JavaScript)
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Configures the Cordova Condo plugin to register a specific event name ('messageReceived') for local notification representation. This allows 'messageReceived' events to trigger local notifications. An event listener is included to log when such events occur.
```javascript
// Register event name for local notification representation
cordova.plugins.condo.debug.setEventNameRegisteredForLocalNotificationRepresentation(
'messageReceived',
true
);
// Now when 'messageReceived' events occur, they can trigger local notifications
document.addEventListener('messageReceived', function(event) {
console.log("Message received event:", event);
});
```
--------------------------------
### Manage Input Focus with Cordova Plugin
Source: https://context7.com/open-condo-software/mobile_cordova_ios_demoapplication/llms.txt
Enables or disables input focus for webkit events using the cordova-plugin-condo. `enableInputs` should be called when an input screen is shown, and `disableInputs` when it's left. This prevents unintended input interactions.
```javascript
// Enable webkit events for input controls (call when showing input screen)
function enableInputs() {
cordova.plugins.condo.setInputsEnabled(
true,
function(response) {
console.log("Inputs enabled");
},
function(error) {
console.error("Failed to enable inputs:", error);
}
);
}
// Disable webkit events (call when leaving input screen)
function disableInputs() {
cordova.plugins.condo.setInputsEnabled(
false,
function(response) {
console.log("Inputs disabled");
},
function(error) {
console.error("Failed to disable inputs:", error);
}
);
}
// Example usage in a form screen
document.addEventListener('DOMContentLoaded', function() {
enableInputs();
});
window.addEventListener('beforeunload', function() {
disableInputs();
});
```
--------------------------------
### Enable Background Bluetooth Central - Cordova JSON Config
Source: https://github.com/open-condo-software/mobile_cordova_ios_demoapplication/blob/main/readme.md
This JSON configuration enables the background Bluetooth central functionality for the cordova-plugin-ble-central. It requires adding the 'bluetooth_central_background' flag to the 'mobile_permissions' array in `www/native_config.json`. This allows the application to continue scanning for Bluetooth devices even when the app is in the background or suspended by iOS.
```json
{
"presentationStyle": "native",
"mobile_permissions": ["bluetooth_central_background"],
"hostApplication": {
"iOS": {
"minimumSupportedVersion": "1.1.22"
}
}
}
```