OS X dev: how to install a new font into the system - swift

First of all, I know about ATSApplicationFontsPath property in Info.plist. But it adds custom fonts just for my application. And I want my app to install some fonts into the OS X during the first launch. That's because my app exports text and I have to make sure that user won't lose proper text formatting opening his file in some other app.
I saw this behavior in Final Draft app. It has custom fonts in its Resources folder. And its Info.plist has no ATSApplicationFontsPath property. But somehow after the first launch Final Draft installs those fonts into the system and uses them.
How is it possible? Didn't come any close to solve this.

You could copy the font files to ~/Library/Fonts or, with admin authentication, /Library/Fonts. You may also need to call CTFontManagerRegisterFontsForURLs() with kCTFontManagerScopeUser to make them immediately available to already-running apps (including your app which installs them).
I recommend that you ask permission from the user before installing anything "permanent" like this outside of your app.

Related

Desktop Sandboxing Issue with Swift macOS

I've been trying to write a Mac app lately, and have run into an issue. This is not overly major but it would be great to have a solution.
I have to load an image at runtime, specified by the user (so no, I cannot embed the image into the bundle as many alternatives suggest), and embed it into an NSTextView using NSAttributedText. The image loads fine from the Pictures directory (/Users/USERNAME/Pictures/IMAGE) etc, but not from the Desktop. I have checked the Capabilities tab in Xcode, and Read/Write is enabled for all of the available options:image
Using FileManager, I have determined that the file definitely exists, but is not readable. Can I set this manually in the Entitlements file?
Thanks in advance.
No, you can't. The standard desktop is not accessible out of the box if the app is sandboxed. Only the standard Downloads, Pictures, Music and Movies folder are accessible with the corresponding entitlement.
There are two options to access the other folders but in all cases the user must choose them once
Open/Save dialog for temporary access if the appropriate entitlement is set.
A security scoped bookmark for permanent access but also in this case the user must first choose the folder once via Open/Save dialog and the security scoped bookmark must be created programmatically.

Swap default iOS system font in apps

I'm trying to build an app to install a custom set of fonts for other ios apps to use. Is it possible to change iOS 6 default set of fonts and add a custom set of font that other apps can use?
Custom (non-system) fonts must be included in an app's .plist file and must be included in the application bundle for an app to use them.
Since application bundles are read only, it is only possible for an app to use a non-system font that is included before it is distributed.
No, it's not. Apps basically can't change default configuration (like fonts, background, colors, icons, animations) from the whole OS. You can use custom fonts in your app though.

iPhone - Change icon of the app programmatically at runtime

I can read that changing the app icon programmatically at runtime is not possible, at least since iOS 3.0.
But... I regulary can see on "App" websites apps that can put icons on the springboard. The first I remember is that kind of app that you give a friend's picture from your album, and it creates an icon so you can call him just clicking on that icon:
http://itunes.apple.com/fr/app/speedtouch-the-best-home-screen/id378360978?mt=8
http://itunes.apple.com/fr/app/desktop-shortcut/id421701004?mt=8
http://itunes.apple.com/fr/app/appbutler-app-organizer/id327391626?mt=8
http://itunes.apple.com/fr/app/tap4music/id365578914?mt=8
So I guess, is it still impossible to change the app icon programmatically at runtime?
Update
Apple have changed this, you can do this now: https://developer.apple.com/documentation/uikit/uiapplication/2806818-setalternateiconname
Original Answer
What you're thinking of here are WebClips, which are basically shortcuts to websites on the home screen. An actual application cannot change it's icon at runtime, as it's defined in the static Info.plist file.
The only exception to this rule is Newsstand applications.
This is now possible in iOS 10.3 using the UIApplication.setAlternateIconName(_:completionHandler:) API.
See my answer to this question: https://stackoverflow.com/a/44966454/233602
Changing your actual icon (other than, e.g, badging) would require changing the app bundle. I'm pretty sure that you don't have write access to the bundle, and in any event this should change the code signature, causing the OS to prevent launching.
So, no. Apps can put links to web sites, but not change their own app.

How do I change the default icon of iPhone application programmatically?

My question is about changing default icon.png content programmatically.
I have free application with Icon (with Lite/Free word inside)
I have In-App purchase inside this app (buy full version)
I click and accept this purchase
Some app content is unlocked
Also, I want my default Icon.png to be changed as well (replace it with NON Lite/Free word inside for example)
I saw this approach in some games but did not buy them to see the results.
You cannot change the application's icon at runtime. This is because it is in the application's bundle, which cannot be modified. Access to the application's bundle is restricted for security. Each bundle is code-signed by a certificate obtained through Apple's developer portal, which guarantees this condition.
To conclude, any files inside the application's bundle, like icons, or the Info.plist file, cannot be changed.
I am sure since you have purchased it you don't have source code.. but still try to look for image icon which must be in application folder.. just delete that icon and put whatever image you want with the same image name.. Also for that one.. you might have to install folder navigation icon. And then you can look in which folder it is install.. I ain't sure but it might be something called /app or /data. I am most of the time playing with android so I know for android where to look.
Thanks

How do I make iPhone SpringBoard show two or more icons for one application bundle?

It seems like Info.plist file has an ability to declare different roles for the same application bundle through the UIRoleInfo key. SpringBoard can recognize these roles after installing an app and may display separate icons for each application role.
For instance, iPhone shows MobileSlideShow.app as 2 different programs: Photos and Camera.
Unfortunately, there is no official Apple documentation about the subject at the moment. Would anybody advise how to organize the same behavior in a custom app?
This feature is going to be used in the Enterprise product for ad hoc distribution.
This isn't a supported feature, so if you do this you might have a hard time getting your app through the approval process. I wouldn't recommend using it.
Have you tried it to see if it works? If it doesn't work, you could create a second app that does nothing but launch the first one, with a custom URL scheme. The first app can recognize when it is being launched with that URL. This is not ideal as you will see the second app launch & quit (though it should be really fast).