PrideChung / FontAwesomeKit

Icon font library for iOS. Currently supports Font-Awesome, Foundation icons, Zocial, and ionicons.
MIT License
2.81k stars 308 forks source link

'Font file doesn't exist' error #26

Open jemgold opened 10 years ago

jemgold commented 10 years ago

I'm getting a weird error - looks like the fonts aren't being registered properly? Doing this in my AppDelegate as a workaround as detailed in KnownIssues

#import <FontAwesomeKit/FontAwesomeKit.h>

@implementation IATAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FAKFontAwesome iconFontWithSize:1];
  [FAKFoundationIcons iconFontWithSize:1];
  [FAKIonIcons iconFontWithSize:1];

  return YES;
}

@end
2014-08-05 18:41:42.958 Visit[74417:60b] *** Assertion failure in +[FAKFontAwesome registerIconFontWithURL:], /Users/jon/code/Visit/Pods/FontAwesomeKit/FontAwesomeKit/FAKIcon.m:14
2014-08-05 18:41:42.962 Visit[74417:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Font file doesn't exist'
*** First throw call stack:
(
    0   CoreFoundation                      0x032781e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x02f5a8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x03278048 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x0115a4de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   Visit                               0x001c1572 +[FAKIcon registerIconFontWithURL:] + 370
    5   Visit                               0x001a3548 __35+[FAKFontAwesome iconFontWithSize:]_block_invoke + 152
    6   libdispatch.dylib                   0x038264d0 _dispatch_client_callout + 14
    7   libdispatch.dylib                   0x03815e12 dispatch_once_f + 184
    8   libdispatch.dylib                   0x03815d55 dispatch_once + 31
    9   Visit                               0x001a333d +[FAKFontAwesome iconFontWithSize:] + 173
    10  Visit                               0x0000371f -[IATAppDelegate application:didFinishLaunchingWithOptions:] + 2543
    11  UIKit                               0x019e514f -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
    12  UIKit                               0x019e5aa1 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1810
    13  UIKit                               0x019ea667 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    14  UIKit                               0x019fef92 -[UIApplication handleEvent:withNewEvent:] + 3517
    15  UIKit                               0x019ff555 -[UIApplication sendEvent:] + 85
    16  UIKit                               0x019ec250 _UIApplicationHandleEvent + 683
    17  GraphicsServices                    0x04272f02 _PurpleEventCallback + 776
    18  GraphicsServices                    0x04272a0d PurpleEventCallback + 46
    19  CoreFoundation                      0x031f3ca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    20  CoreFoundation                      0x031f39db __CFRunLoopDoSource1 + 523
    21  CoreFoundation                      0x0321e68c __CFRunLoopRun + 2156
    22  CoreFoundation                      0x0321d9d3 CFRunLoopRunSpecific + 467
    23  CoreFoundation                      0x0321d7eb CFRunLoopRunInMode + 123
    24  UIKit                               0x019e9d9c -[UIApplication _run] + 840
    25  UIKit                               0x019ebf9b UIApplicationMain + 1225
    26  Visit                               0x00002cfd main + 141
    27  libdyld.dylib                       0x03a5b701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
PrideChung commented 10 years ago

You didn't use those workaround macros, right?

jemgold commented 10 years ago

Nope - just the +iconFontWithSize:1 workaround

PrideChung commented 10 years ago

When this assertion is failed, it means the font file doesn't exist in the app bundle, maybe you removed the font file from the "Copy Bundle Resources" build phrase accidentally. You can also try to clean the project and Xcode derived data, if you're using CocoaPods, try to reinstall. By the way, are you using any font related stuff?

jemgold commented 10 years ago

Thanks, will have a go with those suggestions - in the meantime I switched to a different FontAwesome implementation but will make some time to switch back :)

Jon Gold

jon.gd +447722118382

On 7 August 2014 16:35, Pride Chung notifications@github.com wrote:

When this assertion is failed, it means the font file doesn't exist in the app bundle, maybe you removed the font file from the "Copy Bundle Resources" build phrase accidentally. You can also try to clean the project and Xcode derived data, if you're using CocoaPods, try to reinstall. By the way, are you using any font related stuff?

Reply to this email directly or view it on GitHub https://github.com/PrideChung/FontAwesomeKit/issues/26#issuecomment-51488892 .

ldong commented 9 years ago

I run into the same problem, here is how I solved it.

  1. Build Phases - > Copy Bundle Resources -> '+' -> Add Others -> Select the "FontAwesome.otf" file
  2. Clean Project("CMD + SHIFT + K")
  3. Build and run.
fernandodev commented 9 years ago

I had the same problem.

To solve it, I imported each font resource to my project. I'm using Cocoapods with use_frameworks!. Because frameworks are dynamic they need a bundle resource. FontAwesomeKit doesn't have yet

alex4814 commented 9 years ago

@ldong Right way to solve it. BTW, could it be solved when use_frameworks! is set using cocoa pods

cincas commented 9 years ago

Had a similar issue in my another pod. solved by using this

[[NSBundle bundleForClass:[self class]] URLForResource:@"configuration" withExtension:@"plist"]

And this works for use_frameworks!

So I guess this issue can be fixed by this

// FAKFontAwesome.h
+ (UIFont *)iconFontWithSize:(CGFloat)size
{
#ifndef DISABLE_FONTAWESOME_AUTO_REGISTRATION
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [self registerIconFontWithURL:[[NSBundle bundleForClass:[self class]] URLForResource:@"FontAwesome" withExtension:@"otf"]];
    });
#endif

    UIFont *font = [UIFont fontWithName:@"FontAwesome" size:size];
    NSAssert(font, @"UIFont object should not be nil, check if the font file is added to the application bundle and you're using the correct font name.");
    return font;
}

or use this workaround

[FAKIcon registerIconFontWithURL:[[NSBundle bundleForClass:[FAKFontAwesome class]] URLForResource:@"FontAwesome" withExtension:@"otf"]];
cincas commented 9 years ago

I think this issue can be closed now.

Just checked in last version, it is using bundleForClass now.

chrischenyc commented 9 years ago

@cincas check: https://github.com/PrideChung/FontAwesomeKit/blob/2.2.0/FontAwesomeKit/FAKIonIcons.m

it's still using [NSBundle mainBundle]

cincas commented 9 years ago

@chenyuan I guess you were trying to say "it is still using [NSBundle mainBundle]" right?

check out the master branch. I think they havent released the new version number with this fix.

I'm using pod "FontAwesomeKit", :head as solution atm.

chrischenyc commented 9 years ago

@cincas thanks, your are right, corrected the comment

Ziewvater commented 9 years ago

I've run into this issue as well after switching my project to to use use_frameworks!. My version of the cocoapod is up to date, is the workaround just to manually register the font file?

Edit: Just tried pointing my podfile to the most recent commit on this repo, as mentioned above. Seems to have solved the problem by including this pull request: https://github.com/PrideChung/FontAwesomeKit/pull/32. When will the pod be updated with this?

cincas commented 9 years ago

@Ziewvater you can use pod "FontAwesomeKit", :head as a workaround.

master has been updated to use bundleForClass: instead of mainBundle

tomoyuki28jp commented 9 years ago

@cincas pod "FontAwesomeKit", :head works for me. Thanks a lot!

tomoyuki28jp commented 8 years ago

pod "FontAwesomeKit", :head used to work for me. But when I update xcode and cocoapods, it stops working.

env

OS X Yosemite Xcode 7.2.1 cocoapods 1.0.0.beta.4

cocoapods

  pod 'FontAwesomeKit/FontAwesome',
      git: 'https://github.com/PrideChung/FontAwesomeKit.git'

NOTE: :head does not work with the latest version of cocoapods.

error

2016-02-29 12:53:25.594 App[38801:229238] *** Assertion failure in +[FAKFontAwesome registerIconFontWithURL:], /path/to/App/ios/Pods/FontAwesomeKit/FontAwesomeKit/FAKIcon.m:14
2016-02-29 12:53:25.618 App[38801:229238] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Font file doesn't exist'
ngheungyu commented 8 years ago

@tomoyuki28jp you should be using the following as of cocoapod 1.0, cheers

pod 'FontAwesomeKit/FontAwesome', :git => 'https://github.com/PrideChung/FontAwesomeKit.git'

manan280194 commented 8 years ago

Solved: It was already available in pods bundle I imported the

FontAwesome.otf

file in my main bundle and it worked.