PrideChung/FontAwesomeKit

How to get FontAwesomeKit to work in Extension via Cocoapods

vinced45 opened this issue · 10 comments

I keep getting an error "Font file doesn't exist" when trying to use FontAwesomeKit in App Extensions. How do I get this to work? Thanks

I think that's because FontAwesomeKit is trying to load the font file from the main bundle, but that won't work in the extension environment. Someone else has made a pull request and I've merged it in the master branch, but I don't have the time to test it yet.

Hi @PrideChung ! I love your library and have been using it for a year in my iOS app. I really want to use your library in my WatchKit app, but I'm facing the same issue as @vinced45. Can you provide any tips how to get it to work? I am using Cocoapods and was hoping it would just work, but I get the "Font file doesn't exist" error and even if I manually add the font file to the extension target, the icons are loading and show as a box with a weird X like symbol in them. With the release of the Apple Watch in a couple weeks, it would be really great to be able to continue using this library.

Thanks for your work, FAK is an indispensable part of my tool kit and my apps would be ugly without all your hard work =)

@matthewkrueger I'm so sorry for being absence lately. WatchKit compatibility is a big deal not doubt. My vacation is over and I will start closing issues.

You rock @PrideChung ! If you can post here again and tag me when you get it working, I'd be glad to try it out right away, and write up a blog post about it to get it more exposure. I think you have the best icon kit available and it's going to be so pretty on the Apple Watch.

It's not a perfect solution, but I ended up getting it to work by adding the fonts I was using to "Build Phases > Copy Bundle Resources" by clicking the + button > Add Other and navigating to where the font was stored in the Pods directory.

image

I also tried to get it to work by copying the "Embed Pods Resources" build phase from my main target so I wouldn't have to do things manually but that gave me a permission error.

(Edit: I was using this for a Keyboard extension, not a watch extension.)

@PrideChung Do you plan to make a release using the bugfix for this issue contained in the masterbranch anytime soon?

I have to use PodAsset to locate the bundle. Then manually patch iconFontWithSize method to get the correct url:

+ (UIFont *)iconFontWithSize:(CGFloat)size
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSBundle* bundle = [PodAsset bundleForPod:@"FontAwesomeKit"];
        NSURL* url = [bundle URLForResource:@"ionicons" withExtension:@"ttf"];
        [self registerIconFontWithURL:url];
    });
}

@haifengkao The current implementation in the master branch already fixes the issue:

+ (UIFont *)iconFontWithSize:(CGFloat)size
{
#ifndef DISABLE_FONTAWESOME_AUTO_REGISTRATION
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [self registerIconFontWithURL:[[NSBundle bundleForClass:[FAKFontAwesome 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;
}

It just has never been released.

Why is it not released?

@haifengkao No idea. Because the developer abandoned the library?