Umair Khan
Umair Khan

Reputation: 51

iOS Keyboard Extension Not Working Correctly in Mail App When Selecting Text

I'm developing a custom keyboard extension for iOS in Swift and have run into an issue specifically when using it within the Mail app. My goal is to select all text around the cursor position (both before and after) and manipulate it. However, the behavior in the Mail app is not as expected, whereas it works correctly in other apps like whatsapp or messages and some other similar apps but in mail app or when we write review on App Store I am not able to get the entire app some times I do and some times it fails miserably,

Following is my code:

    while let previousContext = textProxy.documentContextBeforeInput, !previousContext.isEmpty {
    // Combine context before the cursor with current context
    context = previousContext + context
    startingOffset += previousContext.count
    textProxy.adjustTextPosition(byCharacterOffset: -previousContext.count)
    try? await Task.sleep(nanoseconds: 50_000_000)
}

// Adjust cursor back to the original position
textProxy.adjustTextPosition(byCharacterOffset: context.count)
try? await Task.sleep(nanoseconds: 1000_000_000)

while let nextContext = textProxy.documentContextAfterInput, !nextContext.isEmpty {
    // Append context after the cursor to current context
    forwardContextCount += 1
    context += nextContext
    textProxy.adjustTextPosition(byCharacterOffset: nextContext.count)
    try? await Task.sleep(nanoseconds: 100_000_000)
}

self.promptText = context
self.promptCount = context.count

I appreciate any insights or advice on handling this scenario. Thank you!

Upvotes: 0

Views: 53

Answers (0)

Related Questions