This is a demonstration app showcasing the capacitor-foundation-models plugin capabilities. The app provides a simple interface to test Apple's Foundation Models integration in an Ionic Angular application.
- 🤖 Session Management: Start and manage Foundation Models sessions
- 💬 Text Generation: Send prompts and receive AI-generated responses
- 📋 Schema Creation: Define and use structured output schemas
- 🎯 Riddle Generation: Example implementation using schemas for structured responses
⚠️ Error Handling: Comprehensive error handling with user-friendly alerts- 🔍 Availability Checking: Detect device compatibility before using the plugin
Before running this example app, ensure you have:
- iOS 26.0+ device or simulator
- Apple Intelligence enabled on the device
- Xcode 16+ for iOS development
- Node.js 18+ and npm/pnpm
- Ionic CLI installed globally
-
Install dependencies:
cd example-app npm install -
Build the web assets:
npm run build
-
Sync with Capacitor:
npx cap sync ios
-
Open in Xcode:
npx cap open ios
-
Run on device: Build and run the app on a physical iOS device with Apple Intelligence enabled.
- HomePage (
src/app/home/): Main interface for interacting with Foundation Models - Capacitor Config (
capacitor.config.ts): Basic Capacitor configuration - iOS Project (
ios/): Native iOS project with Foundation Models integration
The app first checks if Foundation Models are available on the device:
const availability = await FoundationModels.checkAvailability();
if (!availability.available) {
// Show appropriate error message
}Starts a Foundation Models session with custom instructions:
await FoundationModels.startSession({
instructions: "You are a helpful assistant. You speak only in Portuguese. Your name is Majúlia."
});Send prompts and receive unstructured responses:
const { response } = await FoundationModels.promptWithoutSchema({
prompt: this.message
});Create schemas for structured outputs:
// Define schema
await FoundationModels.createSchema({
name: 'Riddle',
schema: {
question: 'string',
answers: {
name: 'string',
isCorret: 'boolean'
}
}
});
// Use schema
const { response } = await FoundationModels.promptWithSchema({
prompt: 'Crie uma charada de adivinhação. Crie 3 respostas.',
schema: 'Riddle'
});The app provides a simple interface with the following controls:
- Start Session: Initialize Foundation Models session
- Text Input: Enter prompts for the AI
- Send Message: Send unstructured prompts
- Test With Schema: Create the riddle schema
- Tell a Riddle: Generate structured riddle responses
# Start development server
npm run start
# Build for production
npm run build
# Run tests
npm run test
# Lint code
npm run lint
# Watch for changes
npm run watchSince Foundation Models require iOS 26+ and Apple Intelligence, testing must be done on:
- Physical Device: iPhone 15 Pro/Pro Max or newer, iPad with M1+, or Mac with Apple Silicon
- iOS 26+: Ensure device is running iOS 26 or later
- Apple Intelligence Enabled: Check Settings > Apple Intelligence & Siri
- Verify iOS version is 26.0+
- Check that Apple Intelligence is enabled in Settings
- Ensure you're testing on a compatible physical device
- Try restarting the device if issues persist
- Always call "Start Session" before sending messages
- Check device console for detailed error messages
- Verify the plugin is properly installed and synced
- Ensure schema names are unique
- Verify schema structure matches the expected format
- Create schemas before using them in prompts
- Run
npx cap sync iosafter making changes - Clean and rebuild the iOS project if needed
- Check that all dependencies are properly installed
The app demonstrates various schema patterns:
// Simple object schema
{
question: 'string',
answer: 'string',
confidence: 'number',
isCorrect: 'boolean'
}
// Nested object schema
{
quiz: {
title: 'string',
questions: {
text: 'string',
options: 'string',
correct: 'boolean'
}
}
}You can extend this example by:
- Adding more schema types: Experiment with different data structures
- Implementing conversation history: Store and display previous interactions
- Adding temperature controls: Allow users to adjust response creativity
- Creating specialized prompts: Build domain-specific AI assistants
- Adding voice integration: Combine with speech recognition/synthesis
If you find issues with the example app or have suggestions for improvements, please:
- Check existing issues in the main repository
- Create a new issue with detailed reproduction steps
- Submit pull requests for bug fixes or enhancements
This example app is part of the capacitor-foundation-models plugin and is licensed under the MIT License.


