I've added a custom font TTF file to an app I'm making.
I've also added the UIAppFonts key to the plist, as required.
Now, when I launch the app, it hits the "app is crashing in AppDelegate" breakpoint we all know so well.
I can't figure out a way to inspect the exception, but what's stranger is that if I play it through, the app continues just fine -- even allows me to debug. On top of that, the font in question is actually loaded, so there doesn't seem to be any issue there either. Not sure where to start looking for this one.
The font file is probably not added to the target.
Please remove the white spaces from the font file name. And change name in info.plist file.
And Use the same font name which in in the .ttf file. For more information you can check NSGOD's Answer here
Do you have a symbolic breakpoint set for "objc_exception_throw"? It will break on all exceptions, including the ones that will be caught by some code's try/catch frame.
Since you are seeing it show the break at UIApplicationMain, it is likely this is the closest source code to the problem. Check the stack frames in the left column to see if there are Apple internal methods being called.
Change the slider at the bottom of the left column in Xcode to show more of the stack frames if some are hidden.
Related
I am using Xcode 6 (GM, I didn't download betas), and I am developing apps for iOS 7+. For all my projects, I just opened the same projects I used to work on in Xcode 5.
In the Breakpoint navigator, I have the All Exceptions breakpoint on. It is set to Break: On Throw. Now, each time I run my app (whether on a device or in simulator), it stops execution on the line return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); in the main() function.
If I press Play to continue program execution twice, the program runs fine. So this doesn't prevent me from working, but it is annoying to have to manually play the execution each time and reset my editors.
I like the behaviors I have set up in Xcode (taking the current editor to where the execution has paused), and having that All Exceptions breakpoint is important IMO. (So I don't want to change those)
By running the same code, with the same environnements, for an iOS 7 target (again, device or simulator), the exception is not thrown.
Any clue what could cause this strange behavior?
As stated in the comments, you should turn off catching the C++ exceptions by editing your All Exceptions breakpoint.
In order to do that, right click on your breakpoint and change Exception from All to Objective-C:
Exceptions in C++ code are part of normal app functionality. However, exception breakpoint is not catching unhandled but every raised exceptions, even when they're handled correctly later on, hence the stop in execution.
TLDR; In my case the cause of problem was missing fonts.
I also had this problem. While #Johnnywho is correct that leaving Exception Breakpoint for Objective-C only, stops the unwanted behaviour, it still does not explain what is the real cause, why does it run without exception on iOS7 and why does this happen only on some projects.
That's why I went on and dissected one of my projects in which I had this problem, until the point where I was able I found the cause. I suppose that there could be more than one cause for this behaviour, but in my case that was missing custom fonts.
Quick way to test it:
Start a new single view project
Enable breakpoint on all exceptions, including C++ (Breakpoints / + / Add Exception Breakpoint)
Drag into the project some custom font (allow copying and check the target to add it to)
Add a label to the view in the main view controller
Choose the custom font for your label (on Xcode 6+ it should show in the font picker as soon as you drag it into the project).
Run the app and confirm that you see the label in your custom font (it seems that we don't need to add the font file name in Info.plist for the key "Fonts provided by application" anymore, if the custom font has been used in a storyboard of xib of the app).
Now remove the custom font from your project (either by unticking target relationship or by removing it in target settings / Build Phases / Copy Bundle Resources)
Delete the app from your device or sim (to delete the font file from the app bundle)
Product / Clean
Run the app again (now the label still has the reference to the custom font but the app does not have the file for it). You should notice the mysterious exception if you run on iOS8.
Run the app on device with iOS7 or sim with iOS7 (you'll need to change the iOS Deployment Target to iOS7 for that). Although the label won't show the custom font, there won't be an exception.
Add the font file back to the target and the breakpoint does not stop on run anymore.
So my conclusion is that on iOS8 the missing fonts cause C++ exception while on iOS7 they don't, hence the breakpoint trigger.
Similar exception (and breakpoint trigger) can also be caused by incorrectly written font file name in Info.plist file under the key "Fonts provided by application".
Just summarized previous answers which helped me to fix it.
Problem: When you add custom font and then apparently delete (replace) it, somewhere in project is still his reference and the breakpoint stops several times at main C++ lib breakpoint stops in iOS 8.
Solutions
1) Find in project and delete (replace) all references to those fonts. Might in some nibs, submodules, etc…
2) If you can’t fix everywhere (e. x. read-only libs use them) or problem still exists after solution 1 , add those old fonts back to project
3) Ignore it - It is C++ lib so change breakpoint exception from “All" to "Objective-C" only
Xcode 9, sometimes there are exceptions that are thrown but iOS is catching it gracefully. This will help
source
for my case, it was a user-defined attribute in nib
I had a same issue, the issue was i have added some interface files from other project which has different font in it. Just find them and remove.
I have an app with a main.storyboard with a scene correctly set as the initial view controller. When I start the app and run it, this scene comes up as expected.
My problem occurs when I attempt to add custom fonts to the project. When I edit my info.plist to include the fonts in the Fonts provided by application section and then attempt to run the app, it remains stuck on the launch screen and the initial scene from the storyboard is never loaded. If I then remove the Fonts provided ... section from my info.plist file and run it again, the initial screen loads up as expected.
What am I doing wrong here? Does it matter where in the plist the entry is (like at the top or at the bottom)?
So, I discovered that my code was hanging/freezing completely when attempting to call CGFontCreateWithDataProvider (which is a necessary part of registering custom fonts). This was being called before anything else was loaded, so the freezing on this call was preventing the main screen from ever appearing.
The "fix" (gleaned from nearly-unrelated posts) was to add this line prior to the call(s) to CGFontCreateWithDataProvider:
UIFont.familyNames() // you don't need to iterate this array or do anything with it
No more hanging, app starts up as before and custom fonts all work properly.
I've tried looking for info on how to set these (in red) using CMake but have had no luck so far:
1st red box issue:
First of all, even though the device seems like it's been set to 'Universal' correctly, the value isn't being interpreted correctly by Xcode. When I set it to 'Universal' manually using the dropdown, it gives a tab each for iPhone and iPad. Furthermore, I know it's not being interpreted correctly as the app does not function correctly (in my case, neither the launch image nor the app itself run full screen).
I don't think setting orientation programmatically is an option for me since I need the launch image in the correct orientation as well.
So can't do something like this:
How do I programmatically set device orientation in iOS7?
2nd red box issue:
I use an asset file for all my icons, so at the moment I'm having to build using CMake and then press 'Use Asset Catalog' each time.
I found this but doesn't seem very useful:
http://cmake.3232098.n2.nabble.com/Icon-and-Launch-image-support-for-iOS-apps-td7590970.html
Regarding the "1st box issue", I've found that the approach taken by this demo project works really well.
https://github.com/forexample/testapp/blob/master/CMakeLists.txt
They use a templated Info.plist to inject the bundle identifier, etc, during configure. The nice part is then you can modify the orientations in the plist.in file, and then these get translated cleanly to the Info.plist once you open the project.
Regarding the 2nd red box issue, i found that the attribute I needed to set was XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME
For example:
set_target_properties(${TARGET} PROPERTIES
XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
For Launch Images I got it to work by setting it in the plist.in file under UILaunchStoryboardName as described in yano's previous answer.
I am using Xcode 6 (GM, I didn't download betas), and I am developing apps for iOS 7+. For all my projects, I just opened the same projects I used to work on in Xcode 5.
In the Breakpoint navigator, I have the All Exceptions breakpoint on. It is set to Break: On Throw. Now, each time I run my app (whether on a device or in simulator), it stops execution on the line return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); in the main() function.
If I press Play to continue program execution twice, the program runs fine. So this doesn't prevent me from working, but it is annoying to have to manually play the execution each time and reset my editors.
I like the behaviors I have set up in Xcode (taking the current editor to where the execution has paused), and having that All Exceptions breakpoint is important IMO. (So I don't want to change those)
By running the same code, with the same environnements, for an iOS 7 target (again, device or simulator), the exception is not thrown.
Any clue what could cause this strange behavior?
As stated in the comments, you should turn off catching the C++ exceptions by editing your All Exceptions breakpoint.
In order to do that, right click on your breakpoint and change Exception from All to Objective-C:
Exceptions in C++ code are part of normal app functionality. However, exception breakpoint is not catching unhandled but every raised exceptions, even when they're handled correctly later on, hence the stop in execution.
TLDR; In my case the cause of problem was missing fonts.
I also had this problem. While #Johnnywho is correct that leaving Exception Breakpoint for Objective-C only, stops the unwanted behaviour, it still does not explain what is the real cause, why does it run without exception on iOS7 and why does this happen only on some projects.
That's why I went on and dissected one of my projects in which I had this problem, until the point where I was able I found the cause. I suppose that there could be more than one cause for this behaviour, but in my case that was missing custom fonts.
Quick way to test it:
Start a new single view project
Enable breakpoint on all exceptions, including C++ (Breakpoints / + / Add Exception Breakpoint)
Drag into the project some custom font (allow copying and check the target to add it to)
Add a label to the view in the main view controller
Choose the custom font for your label (on Xcode 6+ it should show in the font picker as soon as you drag it into the project).
Run the app and confirm that you see the label in your custom font (it seems that we don't need to add the font file name in Info.plist for the key "Fonts provided by application" anymore, if the custom font has been used in a storyboard of xib of the app).
Now remove the custom font from your project (either by unticking target relationship or by removing it in target settings / Build Phases / Copy Bundle Resources)
Delete the app from your device or sim (to delete the font file from the app bundle)
Product / Clean
Run the app again (now the label still has the reference to the custom font but the app does not have the file for it). You should notice the mysterious exception if you run on iOS8.
Run the app on device with iOS7 or sim with iOS7 (you'll need to change the iOS Deployment Target to iOS7 for that). Although the label won't show the custom font, there won't be an exception.
Add the font file back to the target and the breakpoint does not stop on run anymore.
So my conclusion is that on iOS8 the missing fonts cause C++ exception while on iOS7 they don't, hence the breakpoint trigger.
Similar exception (and breakpoint trigger) can also be caused by incorrectly written font file name in Info.plist file under the key "Fonts provided by application".
Just summarized previous answers which helped me to fix it.
Problem: When you add custom font and then apparently delete (replace) it, somewhere in project is still his reference and the breakpoint stops several times at main C++ lib breakpoint stops in iOS 8.
Solutions
1) Find in project and delete (replace) all references to those fonts. Might in some nibs, submodules, etc…
2) If you can’t fix everywhere (e. x. read-only libs use them) or problem still exists after solution 1 , add those old fonts back to project
3) Ignore it - It is C++ lib so change breakpoint exception from “All" to "Objective-C" only
Xcode 9, sometimes there are exceptions that are thrown but iOS is catching it gracefully. This will help
source
for my case, it was a user-defined attribute in nib
I had a same issue, the issue was i have added some interface files from other project which has different font in it. Just find them and remove.
OK, so I've done a lot of reading, followed several tutorials, and I still cannot add a custom font to my iOS app.
I've (1) added and copied the fonts to xcode.
I've (2) added them to the correct target.
I've (3) made sure they are included as resources in the bundle.
I've (4) included them in my info.plist.
I've (5) tried to find them in my list of fonts by inserting this code.
Yet the fonts STILL do not appear. I recognize that the font name is not the same as the file name, but I compared the list of font family names and font names from before and after, and they are the exact same, proving no fonts were added. I've followed SO and these tutorials to a T but nothing is working.
You inadvertently added them to the wrong (Test) Info.plist.