> ## Documentation Index
> Fetch the complete documentation index at: https://docs.learnway.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Mobile App Integration Guide

> Guidelines and best practices for integrating the LearnWay Flutter mobile application with the backend API.

# Mobile App Integration Guide

This guide details best practices for Flutter / Mobile developers building against the LearnWay Backend.

***

## 1. Network & Base URL Configuration

* **Development (iOS Simulator)**: `http://localhost:3000` or `http://127.0.0.1:3000`
* **Development (Android Emulator)**: `http://10.0.2.2:3000`
* **Staging / Production**: `https://api.learnway.xyz`

All endpoints are strictly namespaced under `/api/v2/`.

***

## 2. Localization Header

To receive content translated into the user's selected language, pass the `Accept-Language` header in every request:

```http theme={null}
Accept-Language: es
```

Supported language codes include `en`, `es`, `fr`, `pt`, `sw`, `ar`, `id`, and `hi`.

***

## 3. WebSockets Connection in Flutter

Use `socket_io_client`:

```dart theme={null}
import 'package:socket_io_client/socket_io_client.dart' as IO;

IO.Socket socket = IO.io('https://api.learnway.xyz/quiz-battle', 
  IO.OptionBuilder()
    .setTransports(['websocket'])
    .setAuth({'token': accessToken})
    .enableAutoConnect()
    .build()
);

socket.onConnect((_) => print('Connected to Quiz Battle Gateway'));
socket.on('match_found', (data) => handleMatch(data));
```

***

## 4. Push Notification Device Registration

Upon receiving an FCM token on device startup, register it immediately:

```http theme={null}
POST /api/v2/notifications/device-token
Authorization: Bearer <token>
Content-Type: application/json

{
  "token": "fcm_device_token_string",
  "deviceType": "ios" // or "android"
}
```
