2

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

sheko
  • 398
  • 3
  • 12
  • 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 05 '22 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 05 '22 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 05 '22 at 17:40
  • @rekopeek, Try my solution, it works. – Andy Jazz Feb 06 '22 at 13:17

1 Answers1

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:

import UIKit

#if canImport(RealityKit)
import RealityKit
import Combine

@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
import SceneKit

#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

Andy Jazz
  • 36,357
  • 13
  • 107
  • 175
  • It works. I tested it. There are no errors. – Andy Jazz Feb 06 '22 at 12:38
  • Import your scene as USDZ from Reality Composer, or save it as USD (USDA, USDC, USDZ) in Maya. https://stackoverflow.com/questions/50846627/how-to-create-usdz-file-using-xcode-converter/50867018#50867018 – Andy Jazz Feb 07 '22 at 20:05
  • @rekopeek, Create a new question and publish your code... – Andy Jazz Feb 08 '22 at 17:05
  • Please, do not edit THIS question! Publish a NEW one!!!! – Andy Jazz Feb 08 '22 at 17:09
  • Scene can crash in several cases: for instance if url is wrong... – Andy Jazz Feb 08 '22 at 18:16
  • At first I should say that you have an error "Matrix" vs "matrix". – Andy Jazz Feb 08 '22 at 18:22
  • "Matrix" is `.rcproject` not `.usdz` !!!! – Andy Jazz Feb 08 '22 at 18:44
  • You must "thank" me with the whole development team now. I mean upvoting my answers )))) – Andy Jazz Feb 08 '22 at 18:53
  • 1
    OK. However, read both my posts carefully – with links. – Andy Jazz Feb 08 '22 at 19:53
  • I've updated the answer. – Andy Jazz Feb 08 '22 at 20:06
  • @rekopeek, I don't understand what you're talking about. My code works, there are no any issues... – Andy Jazz Feb 08 '22 at 23:44
  • can you check https://stackoverflow.com/questions/71110031/realitykit-feature-crashes-on-ios-13-4-1-but-works-in-15-2 – sheko Feb 14 '22 at 11:15
  • Hi @rekopeek, I tried to solve your problem, but I haven't found a solution yet... – Andy Jazz Feb 17 '22 at 14:18
  • AAndy Did you get the same case as i'm , the answer works for 15.2 but not for 13.4.1 it's very strange on running with real devices , btw i'm waiting for you – sheko Feb 17 '22 at 14:47
  • As I said earlier, it worked for me on iOS 15.2, but you're right – it doesn't work on 13.4. Really strange... – Andy Jazz Feb 17 '22 at 14:51
  • AAndy did you tried anything ? – sheko Feb 21 '22 at 10:58
  • Hi @rekopeek, unfortunately I haven't tried to run it in recent days as I have a busy schedule... – Andy Jazz Feb 22 '22 at 07:58
  • Hey @rekopeek, in Xcode 13.3 RC, there's a project setting that could help – `OTHER_LDFLAGS = -weak_framework RealityFoundation`. https://developer.apple.com/documentation/xcode-release-notes/xcode-13_3-release-notes – Andy Jazz Mar 10 '22 at 14:59
  • AAndy we did it in step 3 in your answer , aren't we ? if not where i could add this code ? BTW i already add `RealityFoundation` as weak – sheko Mar 13 '22 at 22:09
  • Note the usdz/.rcproject file is the rug on the video i have commented here my goal when the user changes device heading to some point to show/hide that rug this is the idea of the feature that i need – sheko Mar 13 '22 at 22:33
  • I think they previously add the rug to the space and manage the rotation/movement but i don't know what framework they use and how they use it ? – sheko Mar 13 '22 at 22:36
  • @rekopeek, I added "new" command `OTHER_LDFLAGS = -weak_framework RealityFoundation` on 10th March, if it's the same – OK )) – Andy Jazz Mar 14 '22 at 08:57
  • It's hard to say what it's based on: ARSCNView or ARView, and much harder to guess what developer may use in their app. – Andy Jazz Mar 14 '22 at 10:08
  • Hi @rekopeek! Sorry, I have VERY busy schedule until April 2023. – Andy Jazz Mar 16 '22 at 10:50