3

I have an iOS app with deployment target iOS 10+, I need to add some features that depend only on RealityKit to appear with users whom their iOS version is 13+, the app compiles and runs successfully on real device but the problem is when archiving for upload to AppStore it generates a Swift file and says:

// "No such module RealityKit"

Sure the reason is related to iOS versions <13.0 but I can't edit that file (to add canImport to RealityKit) it's read-only.

My question is how to cross this problem and make it archive successfully with lower versions support?

Here is a demo that shows the problem when archiving Demo.

enter image description here

4
  • Do you have any restriction on why you’re supporting a 5 year old version of iOS that not even Apple supports any more?
    – Fogmeister
    Feb 5, 2022 at 17:29
  • There are many users with iphone 5 and i need to support them as they are dropped at least on ios 11 which also won't solve the current issue
    – sheko
    Feb 5, 2022 at 17:35
  • @Fogmeister can you try the demo may be there is something that can be done in build phases/settings or some where else , i guess it's a problem that opposites backward compatibility and there should be a solution to it ? i posted in Apple forums with no response
    – sheko
    Feb 5, 2022 at 17:40
  • @rekopeek, Try my solution, it works.
    – Andy Jazz
    Feb 6, 2022 at 13:17

1 Answer 1

3

Firstly :

Do not include Reality Composer's .rcproject files in your archive for distribution. .rcproject bundles contain the code with iOS 13.0+ classes, structs and enums. Instead, supply your project with USDZ files.

Secondly :

To allow iOS 13+ users to use RealityKit features, but still allow non-AR users to run this app starting from iOS 10.0, use the following code (CONSIDER, IT'S A SIMULATOR VERSION):

import UIKit

#if canImport(RealityKit) && TARGET_OS_SIMULATOR

import RealityKit

@available(iOS 13.0, *)
class ViewController: UIViewController {
    
    var arView = ARView(frame: .zero)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        arView.frame = self.view.frame
        self.view.addSubview(arView)
                
        let entity = ModelEntity(mesh: .generateBox(size: 0.1))
        let anchor = AnchorEntity(world: [0,0,-2])
        anchor.addChild(entity)
        arView.scene.anchors.append(anchor)
    }
}    
#else

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

#endif

Deployment target is iOS 10.0:

enter image description here

Thirdly :

When publishing to the AppStore (in case we have a deployment target lower than iOS 13.0), we must make the import of this framework weakly linked in the build settings (that's because RealityKit is deeply integrated in iOS and Xcode).

So, go to Build Settings –> Linking -> Other linker Flags.

Double-click it, press +, and paste the following command:

-weak_framework RealityKit -weak_framework Combine

enter image description here

P.S. In Xcode 13.3, there's a project setting that also could help

OTHER_LDFLAGS = -weak_framework RealityFoundation

Fourthly :

So, go to Build Settings –> Framework Search Paths.

Then type there the following command:

$(SRCROOT)

it must be recursive.

enter image description here

Fifthly

The archives window:

enter image description here

27
  • 1
    A demo using RealityKit on ios 10 version. Implement code that can use Secondly code. Jun 20, 2022 at 8:39
  • 1
    Thank you for your help. github.com/7-Yue/RealityKitDemo This is demo. Jun 20, 2022 at 9:38
  • 1
    Hi @ Andy Jazz, do you have some time this week to help me ? Jun 27, 2022 at 1:56
  • 1
    On real device. If i set deployment info to ios 13.0+, it will not crash. But in my develop project, i need adaptor lower version devices. Jun 30, 2022 at 6:12
  • 1
    It's seem like a bug. I have no find the answer to fix it. If you have find it, message to me, please. Jun 30, 2022 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.