Can iOS Today Extension read URL Schemes from app's Info.plist - swift

We have our app target, and in that Info.plist, we defined URL Schemes that can be used to open the app with a URL.
Now we are adding a today extension. We will want to have a table view who will open that URL from the extension. We see how that is supported in the API.
Can we get the URL scheme from the app's Info.plist, or are we basically "hard coding" the value in the extension for it to call to open?

To get infos.plist values you can use this:
let urlTypesArray = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleURLTypes")
You can find the right key (CFBundleURLTypes) opening the info.plist as Source Code (right click)
then, find the value :
let urlSchemesValue = urlTypesArray![0]["CFBundleURLSchemes"]
print("urlSchemesValue => \(urlSchemesValue)")

The answer by #damien is not correct. That will only return the Extension Info.plist file.
The correct answer can be found here in another SO post.

Related

How to change the default URL of thunderclient

Whenever we make a New Request, the default URL in the URL box is
"https://www.thunderclient.com/welcome"
How can we change this with our own URL?
If you want to have a base url. It's super easy in Thunder Client-vs-code.
Firstly, got to Collections
You should have Folder for your project API. And click on ... icon and got to Settings will move to Collection Settings
Secondly, Change the Base Url and save it.
You have done.
This feature is already requested in their Github issues but has still not been added yet.
So, the workaround I find is this:
Go to %USERPROFILE%\.vscode\extensions\rangav.vscode-thunder-client-1.18.7\dist for Windows.
Or go to $HOME/.vscode/extensions/rangav.vscode-thunder-client-1.18.7/dist for Mac or Linux.
Open extension.js file with Notepad or any text editor.
Find and replace this https://www.thunderclient.com/welcome with your desired URL.
Save the file and restart VS Code.

How to Localize NSPhotoLibraryUsageDescription key (ALAssets)

I'm trying to localize the NSPhotoLibraryUsageDescription key defined in the application's info.plist file (reference here).
This key gives you a point to provide custom message when the app is first asking for access to your camera roll.
I'm using ALAssetsLibrary to enumerate assets groups (which triggers the access request message to pop-up).
So far my googling doesn't answer how I could achieve this.
I want to avoid localizing the whole info.plist file as it contain a lot more non-locale dependent content.
Anyone already solved this or have hints how to proceed?
There is a file you can create (which may be created for you when you create a project) called InfoPlist.strings. This file is used and localized much like the file Localizable.strings.
In it you would have and entry something like:
NSPhotoLibraryUsageDescription = "Test of new Photos warnings";
Note that there are no quotation marks around the key
I think as long as the key is included in info.plist, it will localized using the value in InfoPlist.string if it is available for the language. Otherwise it will use whatever is defined in info.plist.
I have my note here https://github.com/onmyway133/notes/issues/290, or you will get
Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
Once these issues have been corrected, you can then redeliver the corrected binary.
Make sure
You declare the keys in Info.plist
You localize it in InfoPlist.strings
You don't need double quotes, like "NSPhotoLibraryUsageDescription" = "Test of new Photos warnings";, you can just use NSPhotoLibraryUsageDescription = "Test of new Photos warnings";
The only way to make this work for me was in Xcode to:
1) Go to Project target -> Info-> Localization-> Add localization
Added language there. This operation created the <projectName>/<LanguageInitials>.lproj folder.
2) I created file InfoPlist.strings inside the folder <projectName>/<LanguageInitials>.lproj;
3) I added the text:
NSPhotoLibraryUsageDescription = "<Add your translated text here>";
inside that InfoPlist.strings file.
4) I then added that folder to the project with File -> add new files to the project or drag and drop.
Note: to test this I:
Cleaned cache, set the language on simulator to be the new one, edited the language in scheme to be the new one at running on simulator and restarted the simulator.

Launch Nokia HERE Maps iOS via API

Is there a documented API for launching Nokia's HERE Maps iOS app for turn-by-turn navigation ?
here-place://lat,lon e.g. here-place://48.866833,2.355411
to open Here on a given place.
here-route://lat1,lon1,name1/lat2,lon2,name2
to start turn by turn navigation from lat1,lon1 to lat2,lon2.
here-route:///lat2,lon2,name2
to start a turn by turn navigation from the user location to lat2,lon2.
EDIT: It seems that name fields now support URL percent escaping to encode space and other characters (Tested in Here WeGo v2.0.11. Thank you marcel for the head up).
Changed to here-location://lat,lon,name in the latest versions (probably 1.2 or so). name is optional.
here-place and here-route give Couldn't open link error, so probably syntax changed there. Maybe you can specify addresses there, but it was out of scope of my research.
On HERE WeGo 2.0.20 (537):
Open a URL with a custom here-route URL Scheme:
//mylocation/latitude,longitude
,URLencoded string as the name of the destination
?ref=<Referrer> referrer (and can be something like your app or company name)
&m=w to indicate the routing mode (m=w stands for walk, m=d for drive)
For instance, here-route://mylocation/37.870090,-122.268150,Downtown%20Berkeley? ref=<Referrer>&m=w requests a route by foot to a destination in downtown Berkeley by a company called Referrer.
Source: HERE Developer Mobility On-Demand Technical Solution Paper (page 36)
I've just tested this and it works fine. The most important bit (at least for me) was that /mylocation/ has to be in the URL for HERE WeGo to start navigation from the user's current location (literally the word mylocation has to be there).
You can also use here-route://sourceLat,sourceLon,sourceOptionalName/destLat,destLon,destOptionalName if you don't want to navigate from the user's current location.
I also tested here-location://lat,lon,optionalName and it works fine in the current (latest, see at the top of this answer) version of HERE WeGo (it used to be here-place, but it doesn't work anymore).
URL Scheme for an application can be found in the app's Info.plist. In Info.plist -> URL Types -> URL Schemes -> xxxxx
Extracting bundle contents from ipa is easy. Rename file from .ipa to .zip and unzip to extract contents. Right click on DownloadedApp.app and show package contents. You will find Info.plist, icons, compressed nibs, executable, etc there.
For Nokia HERE Maps app it is nok
#FKDev
Basically you can replace spaces with %20 sign. Found on NSData & NSURL - url with space having problem or Spaces in a NSURL with variables doesn't load
I preferred too use internal converters shown in the examples
Xcode sample
NSString *sUrl = #"here-route:///52.379189,4.899431,Amsterdam Central
sUrl = [sUrl stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [NSURL URLWithString:sUrl];
C# Sample
var sUrl= Uri.EscapeUriString(#"here-route:///52.379189,4.899431,Amsterdam Central");
var url = new NSUrl(sUrl);
Both sample will be here-route:///52.379189,4.899431,Amsterdam%20Central

Changing application CFBundleURLScheme plist entry dynamically (after compilation)

I'm trying to create an iPhone application that will handle a variety of URL Schemes that I will determine dynamically by querying a server.
Is it possible to register for a custom url scheme programmatically? In other words, can you update the CFBundleURLScheme plist entry after the application has been compiled / deployed?
I haven't been able to find any examples of this being done elsewhere, but nor can I find any definitive reasons why this isn't possible.
Many thanks.
I'm sorry, there is no way. You cannot register custom url schemes programmatically. You also cannot edit your Info.plist, application bundles are read-only on the iPhone.
Here is how I solved it for Swift:
var plistPath = NSBundle.mainBundle().pathForResource("Info", ofType: "plist")
var urlStuff = NSMutableDictionary(contentsOfFile: plistPath!)
var urlType = NSDictionary(objectsAndKeys: "com.appprefix.AppName", "CFBundleURLName", NSArray(object: "idofobject"), "CFBundleURLSchemes")
urlStuff?.setObject(NSArray(object: urlType), forKey: "CFBundleURLTypes")
urlStuff?.writeToFile(plistPath!, atomically: true)
NEW ANSWER AS OF 2021
It is now possible to edit your Info.plist before compiling your app using some scripts.
You can refer to this post: Add/Replace URL Scheme in Info.plist using bash script

CFBundleExectuable Error

Can’t install application
The application at /Users/myname/Documents/SDK/iPhoneApplications/x/build/Debug-iphoneos/x.app does not specify a CFBundleExecutable
I don't know what this means or how to fix it. Can anyone help?
It only occurs when trying to build to a device - it is an iPhone 3G running 4.1 and I am using the latest SDK which allows me to build on iOS 4.1
I also faced the same problem and the solution that worked in my case was to add CFBundleExecutable in info.plist.
Here are the steps to do it
Click on the + icon in your info.plist and add CFBundleExecutable as String type.
2.then in its value just add
$(EXECUTABLE_NAME)
and then rebuild your app.
This worked for me and hope it works for you as well. All the best.
This value is specified in your Info.plist file. I would check your target for the debug configuration and make sure you have the correct plist file specified.
Double-click on your target and search for the Packaging section or for Info.plist.
If the plist is correct, check the content of your Info.plist to make sure you have either a value for either key CFBundleExecutable or key Executable file (they are the same value, but can be displayed with raw or friendly labels).
I faced this issue yesterday and I spent more than 6 hours to find the solution, just follow the instruction below.
1- Go to your "TARGETS".
2- Then go to "Build Settings".
3- After that go to "Basic" then "Combined".
4- Then under the Packaging, you will find the "Info.plist File", check here if your file correct or not, if it's not equal to "Your project Name/Info.plist" you must change it to "Your Project Name/Info.plist".
in my case, i have changed "Mach-O Type" to "Static Library", this may lead to the same question. just change it to Executable , worked for me
After you setup CFBundleExecutable to $(EXECUTABLE_NAME), you have to set EXECUTABLE_NAME's value in xcode. Select your target in TARGETS then go in the Build Settings tab and then search for Product Name.
Check that all your schemes product names are specified corretly to avoid any error (shouldn't contain any of the followin caracter \ [ ] { } ( ) + *).