https://kotlinlang.org logo
Join Slack
Powered by
# ios
  • j

    John O'Reilly

    03/25/2025, 5:39 PM
    On Android we have some code that, if some request fails while say offline, kicks off Worker to run as soon as network connection available (and that will run whether app is in foreground or background). I know you can setup background tasks on iOS but doesn't see to offer quite same functionality (and very undeterministic when task will actually run!). Is anyone using any particular approach on iOS for this?
    d
    p
    +3
    • 6
    • 17
  • y

    Yuvaraj

    03/27/2025, 3:37 AM
    How can we access the AVPlayer FullScreen close button?
    x
    • 2
    • 1
  • d

    Dovydas

    03/27/2025, 4:02 PM
    I'm trying to use a variable font on a label in UIKitView, but the variations are not applying. What could I be doing wrong?
    • 1
    • 1
  • m

    Mikolaj

    03/28/2025, 9:30 AM
    Does anyone know how can I read the custom data sent in APN payload (push notification) while app is started from inactive state? Preferrably in kotlin. I've tried to catch it in
    AppDelegate
    (didFinishLaunchingWithOptions, didReceiveRemoteNotifications) and
    UNUserNotificationDelegate
    on kotlin side as well as in swift but with no luck. 🤔 This is a case of user opening app by tapping notification when app was closed completly (not in background)
    f
    • 2
    • 1
  • p

    Patryk Drozd

    04/01/2025, 12:17 PM
    Hey! I am working on integrating SwiftCode (CryptoKit) to my Kotlin Multiplatform Project but somehow I just can't do it. There is an example of
    SwiftChachaPoly
    on the internet but it's outdated. Here is my error and Gradle File. Error Message
    Copy code
    Exception in thread "main" java.lang.Error: /var/folders/4m/c90drcr50gsghb8p86fnn51r0000gp/T/17669576026474868801.m:1:10: fatal error: 'AppleBridge/AppleBridge-Swift.h' file not found
    
    Failed to generate cinterop for :shared:cinteropAppleBridgeIosArm64: Process 'command '/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java'' finished with non-zero exit value 1
    
    :shared:iosArm64Main: cinterop file: /Users/patrykdrozd/Programing/dms-agent/shared/build/libs/shared-iosArm64Cinterop-AppleBridgeMain-1.0.0.klib does not exist
    
    etc
    Gradle File
    Copy code
    listOf(
        iosArm64(),
        iosSimulatorArm64(),
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
            isStatic = true
            binaryOption("bundleId", "shared")
        }
    
        val platform = when (it.name) {
            "iosArm64" -> "iphoneos"
            "iosSimulatorArm64" -> "iphonesimulator"
            else -> error("Unsupported target ${it.name}")
        }
    
        it.compilations.getByName("main") {
            cinterops.create("AppleBridge") {
                val interopTask = tasks[interopProcessingTaskName]
                interopTask.dependsOn(":AppleBridge:build${platform.replaceFirstChar(Char::titlecase)}")
                includeDirs.headerFilterOnly("$rootDir/AppleBridge/build/Release-$platform/include")
            }
        }
    }
    AppleBridge.def File
    Copy code
    language = Objective-C
    package = swift.appleBridge
    
    headers = AppleBridge/AppleBridge-Swift.h
    headerFilter = AppleBridge/*
    
    staticLibraries = libAppleBridge.a
    libraryPaths.ios_x64 = AppleBridge/build/Release-iphonesimulator
    libraryPaths.ios_simulator_arm64 = AppleBridge/build/Release-iphonesimulator
    libraryPaths.ios_arm64 = AppleBridge/build/Release-iphoneos
    
    linkerOpts = -L/usr/lib/swift
    linkerOpts.ios_x64 = -ios_simulator_version_min 13.0 -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/
    linkerOpts.ios_simulator_arm64 = -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/
    linkerOpts.ios_arm64 = -iphoneos_version_min 13.0 -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/
    Update I found that my Xcode project doesn't create folder with a header
    Debug-iphoneos/include/*-Bridging-Header.h
  • j

    John O'Reilly

    04/01/2025, 12:32 PM
    What do folks use for looking at application logs for an iOS app when not connected to the debugger? I've tried
    idevicesyslog
    for example but not showing the logs for some reason
    f
    • 2
    • 4
  • m

    Mikolaj

    04/03/2025, 12:34 PM
    I started getting those weird errors today
    Undefined symbols for architecture arm64
    . Anybody knows how to resolve this? I did not change anything and the build ran fine yesterday 🤔
    d
    • 2
    • 2
  • p

    Patryk Drozd

    04/07/2025, 2:28 PM
    Hey! Did anyone tried to use https://github.com/apple/swift-certificates inside KMP?
    f
    o
    b
    • 4
    • 12
  • p

    Patrick Cavanagh

    04/10/2025, 8:27 PM
    Has anyone managed to squeeze KMP into an App Clip? Seems like a tall task given the overheads of KMP and the 15MB limit if you go for the QR only approach.
    • 1
    • 2
  • d

    darkmoon_uk

    04/12/2025, 10:40 PM
    Long standing workflow issue for me with Kotlin Multiplatform for iOS... When I build for iOS device in Xcode, resulting
    shared
    Kotlin symbols are visible and navigable from Xcode ✅ When building for simulator in Xcode, compilation result remains correct, but Kotlin symbols are unresolvable to the Xcode IDE 🙅 Is there some search path or configuration that can be added to enable awareness of symbols from simulator build paths?
    r
    • 2
    • 1
  • p

    Patryk Drozd

    04/15/2025, 8:58 AM
    Hey, I am trying to use Swift
    thows
    with kotlin. Swift
    Copy code
    @objcMembers public class AESCryptoBridge: NSObject {
        public func test() throws {
            throw CryptoError.invalidData
        }
    }
    On Kotlin I have access to NSError but I have no idea how to use is. Is there any resource that will explain me how to work with?
    Copy code
    AESCryptoBridge().testAndReturnError("I have no idea how to use NSError Pointer here")
    I found this code but alloc is deprecated if I am correct
    Copy code
    val errorPointer: CPointer<ObjCObjectVar<NSError?>> = alloc<ObjCObjectVar<NSError?>>().ptr
    Update: I found the solution 🙂
    Copy code
    val error = memScoped {
        allocPointerTo<ObjCObjectVar<NSError?>>()
    }
    AESCryptoBridge().testAndReturnError(error.value)
    l
    • 2
    • 4
  • d

    Dovydas

    04/16/2025, 5:17 PM
    Hi all, what's the minimal boilerplate code way to define an actual implementation of an expect class straight in swift?
    f
    • 2
    • 2
  • f

    François

    04/19/2025, 8:29 AM
    Hello, a big tip about the completion issue with Xcode. If you’re using custom Xcode configuration (more than Debug/Release), it’s breaking SOURCE_KIT. For fixing this issue, add next to your Compile Kotlin Framework - Build phase. •
    cd "${SRCROOT}/../shared/build/xcode-frameworks/"
    (or any other path to the shared framework •
    ln -Fs "${CONFIGURATION}" "Debug"
    A Debug directory is mandatory for SOURCE_KIT to work!
    🚀 3
  • d

    Dovydas

    04/20/2025, 3:28 PM
    If I have a Kotlin interface with functions or variables that have a body and which I don't want to override, when implementing it in Swift, it requires me to still override everything.
    f
    • 2
    • 4
  • c

    chandilsachin

    04/22/2025, 12:19 PM
    It could be a naive question. Is there a support for adding the breakpoint in kotlin code and debug in xcode? If not then how others are debugging the code? What other solutions are there for the same?
    👍 1
    m
    • 2
    • 3
  • m

    Marc

    04/22/2025, 2:33 PM
    Is there a way to properly export a UByteArray type in an interface to Swift? Unlike a normal ByteArray it just turns into Any instead of KotlinByteArray.
  • m

    Max

    04/22/2025, 6:27 PM
    👀 KMP Classes not visible in Swift by default 👀 Sometimes I face the issue that classes defined in KMP shared code are not visible in Swift. I work around this issue by adding a “fake usage” to the
    MainViewController.kt
    class like below. Afterwards I can access
    IOSPlatformFile
    in Swift code.
    Copy code
    fun MainViewController() = ComposeUIViewController { App() }
    
    // so swift code can access this
    val platformFile: IOSPlatformFile = IOSPlatformFile("")
    Could someone clarify what I’m doing wrong in these cases? Are only classes from the main module visible to Swift by default?
    ✅ 1
    f
    • 2
    • 4
  • h

    Hasan Nagizade

    05/02/2025, 6:50 AM
    I don't know if it's offtopic or not but I need iOS Device Support files for 18.5 (22F5053f). Would be grateful for any help
    m
    • 2
    • 2
  • g

    GNKumar

    05/02/2025, 1:40 PM
    Hi , Team I am working on BLE iOS application. While reading the data from BLE device continuously, I am getting below crash Message from debugger: Terminated due to signal 9 Note: app running in background. Any suggestions on how to resolve it? Thanks, GNKumar.
  • m

    Mikolaj

    05/06/2025, 1:40 PM
    Is there anything I can do to make
    embedAndSign
    run faster (besides buy new computer)? I'm not using cocoapods nor SPM, only kotlin (and minimum swift boilerplate) yet full ios build still takes 20-30 minutes (macbook M3 16GB ram) *embedAndSign takes >50% of that time
    k
    m
    • 3
    • 5
  • f

    Farhazul Mullick

    05/07/2025, 9:24 AM
    Hey, I am using
    kotlin native cocoapods
    . I have few questions. 1. Why kotlin native cocoapods plugin automatically creates podspec file upon sync. 2. If i use some cocoapods dependency and like Alamofire. I can define in gradle inside cocoapods block. Upon gradle sync podInstall task is ran by gradle. Then kotlin files of those pods are generated from cocoapods package. This later compiled with the final fat-framework. We can use this framework in any ios app. If so why we need to create a pod file in iosApp and run pod install there as well?
    f
    • 2
    • 4
  • a

    abraham

    05/09/2025, 2:43 PM
    Hey, sorry if this is a stupid question as I don't know much about iOS development. When I use "jump to definition" in XCode on a (KMP) method or class from code, it will jump to that (basically) unreadable generated header file. However if I do the same on the module import it does show that header in a more human readable format, is there a flag or setting I forgot that parses all those
    swift_name
    attributes?
    m
    • 2
    • 3
  • f

    François

    05/13/2025, 10:37 AM
    Hi everyone, Your SwiftUI Preview are not working well or slow because of infinite Gradle build Framework task? The solution : Check for change inside your shared Kotlin source to avoid useless build! Working only if you’re building a dynamic framework
    Copy code
    CUR="${SRCROOT}/../shared/build/list_of_files.txt"
    OLD="${SRCROOT}/../shared/build/old_list_of_files.txt"
    touch $OLD
    CHANGES="${SRCROOT}/../shared/build/list_of_changes.txt"
    
    ls -lRT "${SRCROOT}/../shared/src/" > $CUR
    diff $OLD $CUR > $CHANGES
    
    if [ ! -s "${CHANGES}" ]; then
      echo "No change in shared source"
      exit 0
    fi
    
    
    if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then
     echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\""
     exit 0
    fi
    cd "$SRCROOT/.."
    ./gradlew :shared:embedAndSignAppleFrameworkForXcode
    
    # set the current change as old after the build is OK
    mv $CUR $OLD
    😮 2
    👍 2
    • 1
    • 1
  • j

    jQrgen

    05/16/2025, 11:01 AM
    How do we know how much stuff we can run in background? iOS sandbox keeps killing our app in background on large network loads for syncing and verification blockchain headers using cryptographic signature verification
    f
    • 2
    • 4
  • f

    F

    05/21/2025, 5:29 PM
    Are there any examples of disabling back on a specific screen using Circuit? i want to disabling the swiping that triggers back on a specifiek screen based on some value.
  • c

    chrisjenx

    05/24/2025, 6:23 PM
    Anyone know how to fix the Dropdown read only selectable text regression on iOS (Regressed 1.7 > 1.8)
    • 1
    • 2
  • v

    Vivek Gupta

    05/27/2025, 10:33 AM
    Can anyone guide/share a demo setup/steps for adding KMM support on existing iOS project ?
    a
    t
    • 3
    • 2
  • r

    Raphael TEYSSANDIER

    05/29/2025, 10:19 PM
    I'm trying to publish a lib that use Room 2.7.1 to maven central, but will using
    publishAndReleaseToMavenCentral
    on github actions. But I get an error for iOS:
    Copy code
    > Task :xxx:compileKotlinIosSimulatorArm64
    e: file:///Users/runner/work/xxx/xxx/xxx/build/generated/ksp/metadata/commonMain/kotlin/io/dot/lorraine/db/XXXConstructor.kt:5:24 'actual object XXXConstructor : RoomDatabaseConstructor<XXXDB>' has no corresponding expected declaration
    e: file:///Users/runner/work/xxx/xxx/xxx/build/generated/ksp/metadata/commonMain/kotlin/io/dot/xxx/db/XXXConstructor.kt:5:24 XXXConstructor: expect and corresponding actual are declared in the same module.
    > Task :xxx:compileCommonMainKotlinMetadata FAILED
    e: file:///Users/runner/work/xxx/xxx/xxx/build/generated/ksp/metadata/commonMain/kotlin/io/dot/xxx/db/XXXConstructor.kt:6:23 'actual fun initialize(): XXXDB' has no corresponding expected declaration
    e: file:///Users/runner/work/xxx/xxx/xx/src/commonMain/kotlin/io/dot/xxx/db/XXXConstructor.kt:6:24 XXXConstructor: expect and corresponding actual are declared in the same module.
    Any idea how to fix it ?
    p
    • 2
    • 5
  • m

    Muaz KADAN

    06/01/2025, 8:26 AM
    Hi, if I want to use compose resources from a KMP module in iOS Do we have something that does what this function does out of the box?
    Copy code
    fun StringResource.localized(): String {
        return runBlocking { getString(this@localized) }
    }
    k
    d
    d
    • 4
    • 5
  • a

    Anant Kumar Gupta

    06/07/2025, 4:21 AM
    Hello guyz, Has anyone encountered this? Is it something to worry about, or is there a better way to safely handle
    CGImage
    in Kotlin/Native? Warning - Cannot access class 'cnames. structs. CGImage' in the expression type. While it may work, this case indicates a configuration mistake and can lead to avoidable compilation errors, so it may be forbidden soon. Check your module classpath for missing or conflicting dependencies.
    Copy code
    fun generateVideoThumbnailIOS(
        uri: String
    ): ImageBitmap? = memScoped {
        val nsUrl = NSURL.Companion.fileURLWithPath(uri.removePrefix("file://"))
        val asset = AVURLAsset.URLAssetWithURL(nsUrl, null)
        val generator = AVAssetImageGenerator(asset)
        generator.appliesPreferredTrackTransform = true
        val requestedTime = CMTimeMake(1, 1).useContents { readValue() }
        val actualTime: CMTime = alloc<CMTime>()
        val errorPtr = alloc<ObjCObjectVar<NSError?>>()
        val cgImage = generator.copyCGImageAtTime(
            requestedTime = requestedTime,
            actualTime = actualTime.ptr,
            error = errorPtr.ptr
        ) ?: run {
            println("Error: ${errorPtr.value?.localizedDescription}")
            return@memScoped null
        }
    
        val uiImage = UIImage.imageWithCGImage(cgImage)
        val nsData = uiImage.pngRepresentation() ?: return@memScoped null
        val length = nsData.length.toInt()
        val bytePtr = nsData.bytes?.reinterpret<ByteVar>() ?: return@memScoped null
        val byteArray = bytePtr.readBytes(length)
        val finalThumbnail = Image.makeFromEncoded(byteArray).toComposeImageBitmap()
        return@memScoped finalThumbnail
    }
    👀 1
    f
    • 2
    • 1