XCode export problems.

Bug Report

1) Camera Access Crash

You recently fixed a bug that caused Codea to crash when the camera didn’t have access. By using cameraSource() you can now check for -1. However, when the project is exported to XCode it will crash with the following error.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureDataOutputSynchronizer initWithDataOutputs:] dataOutputs must all contain a valid connection'

I tried to use a NSSetUncaughtExceptionHandler, but swift wouldn’t catch it and just kept crashing.

2) Missing Assets on Exported Projects

Projects exported to XCode crash because of missing asset. Blocks.assets: Blank White.png If I copy the file by hand and put it in the Assets folder in XCode under the Blocks.assets folder it works. I am not using that asset in my project. I might have used it before, but my code never references it.

3) Font not Being Loaded

The font Inconsolata did not display correctly after being exported to XCode. fontSize() did not effect it so I couldn’t control the size and the font was not correct. I wonder if other fonts are affected by this issue.

4) Dependency Assets not Found

A few weeks ago you added support for Dependencies to use their own assets from their own project’s assets folder. Which works great. When exported and run in XCode the images can not be found.

5) Overlay Displayed while Loading

When a project is loaded on the iPad from XCode no matter the settings, the parameters overlay will show for a second or less and then disappear. I would like the overlay to never be visible.

In the ViewController.swift file you have:

self.setViewMode(CodeaViewModeFullscreenNoButtons, animated: false)

I tried moving it around, but it did not solve the issue. I have `displayMode(FULLSCREEN_NO_BUTTONS) set first thing in my code. But the overlay seems to be displaying while loading the app. Even though I am using a loading screen. On faster devices the overlay only flashes for split second, but it is still visible.

6) Icon not Correctly Set

The app icon doesn’t get set correctly and some sizes didn’t match. But after a little bit of fiddling, I got all the icons setup. I just thought you should know.

End Report

Sorry for posting so many things at once. Today was the first time in a long time I had a chance to work on my project. If you need me to explain more or if I am doing something wrong, let me know!

@Simeon When it comes to Swift, I really don’t know what I am doing.

However, I was able to solve issue 5 by adding self.viewMode = CodeaViewModeFullscreenNoButtons; to the end of viewDidLoad in MyProjectNameViewController.swift

    override func viewDidLoad() {
        initializeRenderer {
            success in
            if !success {
                fatalError("Failed to load Codea project")
        self.viewMode = CodeaViewModeFullscreenNoButtons;

If there is a better way to do it. Let me know!

@exomut there are a couple that are easy to resolve

  1. Ah that might be because I haven’t updated the runtime libraries to match the release version of Codea on the store. Will make a note to do this and let you know when they are up

  2. Hmm this could be some sort of internal dependency by Craft. Thank you for the report

  3. Inconsolata is a custom font (i.e., doesn’t ship with iOS). Luckily, however, it’s free and you can download it and bundle it in Xcode.

To do this, get the ttf https://github.com/google/fonts/blob/master/ofl/inconsolata/Inconsolata-Regular.ttf

Then you need to add a key to your app’s Info.plist, it will be called “Fonts provided by application” (the actual key is UIAppFonts). This should be an array, and in it you should list the ttf filename that is bundled with the app.

  1. Sounds like this might be related to (1)

@Simeon Thanks for the update and the hard work! I will look into 3). I am getting close to releasing an app on the app store. So let me know when you get the runtime libraries updated.

@Simeon I was about to archive my project in XCode and upload to the App store, but the following error came up:

ld: bitcode bundle could not be generated because '/Users/username/app name/AppName/Frameworks/CraftKit.framework/CraftKit' was built without full bitcode. All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build file '/Users/username/app name/AppName/Frameworks/CraftKit.framework/CraftKit' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there a way to fix that from my end, without a Codea update?

Oh damn, sorry about that @exomut I’ll look into it.

@Simeon Thanks! Not having access to the camera causing the app to crash (1) in XCode and the bitcode error are the last 2 things that I need to solve before I release to the app store.

I have been working on and off for a few months on 4 apps for my classroom and I thought it would be fun to try and sell them.

I have dabbled in programming many times over the years. However, Codea is one of the first times I have really had a lot of fun with programming. It is so convenient and portable, simple yet powerful, quick, and so much more. It really is a joy to use. Thank you so much for making such a powerful tool.

The Codea Talk community is great as well. Everyone is calm, listens, and helps. Your replies are always positive and caring even if it is a negative topic. Keep up the wonderful work.

Also, I saw on Twitter you were thinking about moving Codea over to using the iOS file browser. Just like you do with Shade. I would love that, as long as sharing and exporting to XCode are as easy as it is now. It gives more freedom to manage my workflow and files. Working Copy has a nice pop up on long press to allow you to commit. Something similar to that for XCode export would be awesome. However, I feel like you have a lot of thing you are working on right now. It would be nice, but Codea’s file manager, gets the job done.

Take care of your mailbox friend :wink: Keep him warm!

I tried to remove CraftKit for one of my apps that didn’t require it. However, the ToolKit framework had the same bitcode error as well. I am guessing it is the same for the other frameworks as well.

Just thought you should know. :slight_smile:

I tried turning off bitcode in build settings. It allowed me to archive with out errors but then distributing the app to a device or the app store caused XCode to crash.

@exomut I’m having issues even submitting new versions of Codea with bitcode enabled at the moment when using iOS 13 and Xcode 11. Apple rejects the binary in processing:

The app cannot be processed because options not allowed to be embedded in bitcode are detected in the submission. It is likely that you are not building the app with the toolchain provided in Xcode

However I do not have this issue when the binary is produced with Xcode 10. I assume you are using Xcode 10?

I’ve logged this as a bug with them on July 11, but they have not yet gotten back. It seems like something has changed with their App Store intake that is incorrectly flagging the bitcode-including frameworks as if they were not built with the official toolchain.

@Simeon Yes I am using XCode 10. If I have bitcode off, and archive then try to upload to the App store. XCode instantly crashes. After waiting a while I get the send a report message with the following:

NCAUGHT EXCEPTION (NSInvalidArgumentException): *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]

That is just a snippet. It is a very long report, but that seemed like the most important detail.

I am downloading XCode 9 over night (slow internet). I saw some other people having issues with that error on XCode 10. So, I will give that a try and let you know how it goes.

@Simeon After the download failing multiple times. I finally got XCode 9.4.

9.4 Doesn’t support Swift 5. Since the included frameworks were built with Swift 5, XCode wouldn’t allow the app to be build, because XCode 9.4 only supports Swift 4.1.

I am out of ideas for now. If you figure something out, let me know. :slight_smile:

You could try submitting using Application Loader

Go to the Xcode menu → Open Developer Tool → Application Loader

You can export the IPA file from Xcode (distribute it like normal but using Ad Hoc I think…). Then open it in Application Loader to submit to the store

@Simeon Exporting using Development and Ad Hoc all crash, so I am unable to create an IPA.

I tried building the IPA using command line tools, and instead of crashing I was able to get a useful error:

Found an unexpected Mach-O header code: 0x72613c21

After doing a little research, that error is usually related to frameworks overlapping. Every time I build a Codea Project for testing, I get the following warning:

objc[1385]: Class PDFView is implemented in both /System/Library/Frameworks/PDFKit.framework/PDFKit (0x1f15719f8) and /private/var/containers/Bundle/Application/B5431A63-45E6-47BC-8389-0D490CD9E0C0/ProjectName.app/Frameworks/ToolKit.framework/ToolKit (0x10527f698). One of the two will be used. Which one is undefined.

So, right now I am working on suppressing that warning to see if that will fix the crash on export. However, I am having a hard time with solving that PDFView error.

I will continue to try :s If you figured something out let me know.

@exomut I’ll work on this by creating a test app on the store and seeing if I can get it all uploading, then I’ll update the frameworks for you

@Simeon Thank you so much for looking in to it! I have been working on it all day, with no success… I don’t want to push too much, but please make your test app with the cameraSource() == -1 check as well. When testing on actual hardware, it seems to work. But the iPhone simulator always crashes with Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureDataOutputSynchronizer initWithDataOutputs:] dataOutputs must all contain a valid connection' since the simulator never asks for permissions (Might be because I don’t have a camera). I will get the same error on actual hardware if I block camera access.

I want to go back to the fun part of programming… Codea on iPad. I really should learn more Swift and Xcode. Maybe some day those will become fun too. I highly doubt that though.