How to fetch font files otf and ttf on demand to reduce initial download size of the app

Jadhav, Snehal [MN035] 0 Reputation points
2023-02-14T11:37:16.1633333+00:00

We have font files(.otf and .ttf) in our app, which are huge in size. How to fetch font files otf and ttf on demand to reduce initial download size of the app in Xamarin Forms?

we are trying to explore two options for Xamarin.

  1. Can we apply ODR tags to font files and fetch those on demand like here in native iOS?
    Ref link: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/On_Demand_Resources_Guide/
  2. Came across some code samples to do the same in native iOS here without using ODR tags, Can we use the same in xamarin forms to fetch the fonts on demand in Xamarin forms?
    However, as per the the readme file, below are another sets of queries we have.
    1. Do we need user permission to download fonts ?
    2. Do we need to enabled Font capabilities for the same as shown in the below screenshot from the Entitlement.plist ?
      Screenshot 2023-02-14 at 4.47.32 PM
    3. As per ReadMe , The system may decide to remove them under certain usage scenarios, What are those exact scenarios?
Developer technologies | .NET | Xamarin
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-02-15T07:54:23.0833333+00:00

    Hello,
    For the first question, I noticed you have created an issue at GitHub: On demand resources tags are not working from Visual Studio #15692. You can follow the progress at GitHub, and this issue is related to VS, you can also report it at DC, see how to report a problem with the Visual Studio product or installer.

    The second problem is about an Apple's sample, and you want to use the same function in Xamarin forms. The native sample mainly calls the CTFontDescriptorMatchFontDescriptorsWithProgressHandler method. You could use this method in Xamrin.iOS project and invoke the native method via DependencyService with Xamarin.Forms.

    Do we need user permission to download fonts?

    No, there is no such permission.

    Do we need to enabled Font capabilities?

    There is no such capability in the native sample, and the target platform of the sample is before iOS7. I try to adjust the sample and deploy the app on iOS16.0 device, it works fine and doesn't ask for the permissions. You said you have many font files (.otf and .ttf), so you might need to configure custom fonts, and call CTFontManagerRegisterFontsForURL method. If so, you need to enable these font capabilities (iOS 13 and later). Furthermore, you should provide these files for App store review when you publish the app.

    The system may decide to remove them under certain usage scenarios. What are those exact scenarios?

    The sample is a little old, and this supported fonts list [http://support.apple.com/kb/HT5484] is not found. And it's an Apple question, you can create a thread at Apple Developer Forums or connect the Apple developer support for further help.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.