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

sheko
  • 516
  • 4
  • 15
  • 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 (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

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 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
  • 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
  • AAndy did you tried anything ? – sheko Feb 21 '22 at 10:58
  • 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
  • Could you provide a download link for the demo? I tried the above method but it still doesn't work on the mobile device. – Crystal Black Jun 20 '22 at 08:21
  • 1
    A demo using RealityKit on ios 10 version. Implement code that can use `Secondly` code. – Crystal Black Jun 20 '22 at 08:39
  • Could you help me solve this `lower iOS deployment target` problem on a demo? I could provide demo link. Thank you …… – Crystal Black Jun 20 '22 at 08:50
  • 1
    Thank you for your help. https://github.com/7-Yue/RealityKitDemo This is demo. – Crystal Black Jun 20 '22 at 09:38
  • 1
    Hi @ Andy Jazz, do you have some time this week to help me ? – Crystal Black Jun 27 '22 at 01:56
  • Hi @CrystalBlack, I am back. Describe your problem with RealityKit, please. – Andy Jazz Jun 29 '22 at 09:49
  • Have you tried using `-weak_framework RealityKit` in `Build Settings –> Linking -> Other linker Flags` ? – Andy Jazz Jun 29 '22 at 17:01
  • I have tried it. But it not work. – Crystal Black Jun 30 '22 at 01:44
  • Where does the crash occur: on real device or on the simulator? – Andy Jazz Jun 30 '22 at 04:59
  • 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. – Crystal Black Jun 30 '22 at 06:12
  • ...and what about simulator? (At the moment I have only device with iOS 15.5) – Andy Jazz Jun 30 '22 at 06:14
  • Try it in Simulator `#if canImport(RealityKit) && canImport(RealityFoundation) && TARGET_OS_SIMULATOR`. I've updated my answer. – Andy Jazz Jun 30 '22 at 06:31
  • I tried real device and simulator. Both versions are ios15. It's ok. Unfortunately, i just have ios15 simulator. ios 14 is downloading…… If simulator have no this question, but lower version real device still have this question. This seems to be an Apple bug. – Crystal Black Jun 30 '22 at 06:36
  • Use `TARGET_OS_SIMULATOR`. ios14 real deivce will not use RealityKit and RealityFoundation. But it support RealityKit feature. – Crystal Black Jun 30 '22 at 06:41
  • I tried it on Simulator iOS 12.4 (Xcode 13.4) and on Simulator iOS 15.5 (Xcode 13.4). Both work. – Andy Jazz Jun 30 '22 at 06:41
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/246049/discussion-between-crystal-black-and-andy-jazz). – Crystal Black Jun 30 '22 at 06:44
  • At the moment I am at work (sorry). In 15 minutes my lesson starts. – Andy Jazz Jun 30 '22 at 06:46
  • Ok… Is there any other way I can chat with you. – Crystal Black Jun 30 '22 at 06:52
  • @CrystalBlack, Yes, I agree with you... I tried to run the simulator in the morning - and I managed to run it 2 times without errors. But now, I'm trying to do the same - and my app keeps crashing. This is a real challenge for developers. It drives anyone crazy. – Andy Jazz Jun 30 '22 at 10:17
  • 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. – Crystal Black Jun 30 '22 at 11:51
  • Ok, to be continued... ) – Andy Jazz Jun 30 '22 at 11:54