AI Text Autocomplete While Typing for Mobile App

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
AI Text Autocomplete While Typing for Mobile App
Medium
~3-5 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    761
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    649
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1071
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    884
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    466

Implementing AI-Powered Text Autocomplete for Typing in Mobile Applications

Built-in keyboard autocomplete on iOS and Android predicts the next word from frequency n-grams. AI autocomplete understands context: knows the user is writing a business email, sees first two paragraphs, suggests complete phrases, not single words.

The gap between concept and working implementation lies in UX and performance details.

When to offer suggestions

Most underestimated part: the trigger. Suggestion shouldn't appear per character.

Working heuristic: offer autocomplete if user typed 3+ words on current line and paused > 600 ms, or hit space at end of incomplete sentence.

// iOS—autocomplete trigger
private var autocompleteTask: Task<Void, Never>?

func textDidChange(_ textView: UITextView) {
    autocompleteTask?.cancel()

    let text = textView.text ?? ""
    let cursorPosition = textView.selectedRange.location
    let textBeforeCursor = String(text.prefix(cursorPosition))

    // Don't suggest in middle of word
    guard textBeforeCursor.last == " " || textBeforeCursor.last == "\n" else {
        hideAutocomplete()
        return
    }

    // Minimum 15 characters context
    guard textBeforeCursor.trimmingCharacters(in: .whitespaces).count > 15 else { return }

    autocompleteTask = Task {
        try? await Task.sleep(nanoseconds: 600_000_000) // 600ms debounce
        guard !Task.isCancelled else { return }
        await fetchAutocomplete(context: textBeforeCursor)
    }
}

Request to model and response parsing

For autocomplete use completion mode, not chat. gpt-4o-mini with max_tokens: 30 and temperature: 0.3—fast and predictable.

struct AutocompleteRequest: Encodable {
    let model = "gpt-4o-mini"
    let messages: [ChatMessage]
    let maxTokens = 30
    let temperature = 0.3
    let stop = ["\n", "."]  // stop at end of sentence
}

func buildPrompt(context: String) -> [ChatMessage] {
    [
        ChatMessage(role: "system", content: "Complete the text naturally. Continue from where it ends. Output only the continuation, no commentary."),
        ChatMessage(role: "user", content: context)
    ]
}

Stop tokens \n and . matter. Without them, model generates several sentences; we need one continuation.

Alternative for on-device: CreateML Text Classifier doesn't fit; need generative model. iOS 18+ has Foundation Models framework with on-device LLM (Apple Intelligence). Android has Gemini Nano via Google AI Edge SDK:

// Android—Gemini Nano on-device (requires device support)
val generativeModel = GenerativeModel(
    modelName = "gemini-nano",
    generationConfig = generationConfig {
        maxOutputTokens = 30
        temperature = 0.3f
        stopSequences = listOf(".", "\n")
    }
)

val response = generativeModel.generateContent(
    content { text("Complete naturally: $contextText") }
)
val completion = response.text?.trim() ?: ""

Gemini Nano available on Pixel 8+ and some Samsung—not universal. For broad audience, need server fallback.

Display suggestion

Standard pattern: gray inline text after cursor. User presses Tab or swipes right—suggestion accepted. Any other input—hidden.

// Android Compose—inline suggestion
@Composable
fun TextFieldWithSuggestion(
    value: String,
    suggestion: String,
    onValueChange: (String) -> Unit,
    onAcceptSuggestion: () -> Unit
) {
    val annotatedText = buildAnnotatedString {
        append(value)
        withStyle(SpanStyle(color = Color.Gray.copy(alpha = 0.6f))) {
            append(suggestion)
        }
    }

    BasicTextField(
        value = TextFieldValue(
            annotatedString = annotatedText,
            selection = TextRange(value.length)  // cursor after real text
        ),
        onValueChange = { tfv ->
            val newText = tfv.text.take(value.length + suggestion.length)
            if (newText.startsWith(value + suggestion)) {
                onAcceptSuggestion()
            } else {
                onValueChange(tfv.text.take(value.length))
            }
        },
        keyboardActions = KeyboardActions(
            onDone = { onAcceptSuggestion() }
        )
    )
}

iOS inline suggestion via UITextInput + drawText(in:) or simpler overlay label positioned via caretRect(for:).

Common issues

Suggestion flickers. Happens if new request returns faster than 200 ms and replaces previous immediately. Solution: show only if new suggestion differs from previous by > 3 characters.

Model continues deleted text. If user deleted part—context for prompt must be current version, not previous. Track textBeforeCursor sync with actual TextStorage state.

Tab intercepted by system. On Android, Tab on soft keyboard unavailable. Use custom inline key or gesture swipe-right via GestureDetector.

Timeline estimates

Basic autocomplete with server API + inline UI—5–8 days. On-device via Apple Intelligence / Gemini Nano with server fallback—2–3 weeks.