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
Related
I am working on my mobile app and with that I have been using Realm Database to store the user data. Further I have made a application for mac that is supposed to be able to open a realm file and display the user data from the file (Yes I know I can use Realm Studio for this, but I want to be able to develop my own application to add some features that my client needs). Does anyone know how I can open a realmfile on an mac app and make the realm code to use data from that file to fill out my tableview?
Thanks!
EDIT: Sorry for my unclear question. What I want is a way for realm database to get use data from a different file than the "default.realm" file. I have tried to see trough the documentation on realm.io but I could not figure it out, hope this cleared things up!
Based on an edit to the question, I believe the question is how to access a Realm file other than default.realm.
Here's one option; suppose you want to call your realm file todo.realm.
func setRealmFile() {
var config = Realm.Configuration()
// Using the default directory, append todo.realm
config.fileURL = config.fileURL!.deletingLastPathComponent().appendingPathComponent("todo.realm")
Realm.Configuration.defaultConfiguration = config
}
I have file sharing enabled on my app and so, when you view the documents folder in iTunes, there are the Core Data sqlite files siting there just waiting to be fiddled with by the user.
I have found a few discussions on this but, surprisingly, no one seems to address the concerns I have.
Some say to 'move' them to the library folder - in a custom sub-directory, and another says just rename the files prefixing each with a period.
Both options sound lovely, but these are essential OS files!
So my first question is, if you do either of these things (with NSFileManager.defaultManager() - I presume), will the app just automatically find them afterwards? ...or is there a specific 'way' in which you do (either of) them ...so that the app finds them afterward?
Any responses, if you could demonstrate using Swift rather than Objective C, that would be appreciated! Thanks, :)
Figured it out:
To anyone wondering the same thing (which I have seen many doing),
In my app delegate > in the 'persistentStoreCoordinator' lazy variable,
I changed the following line of code:
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("MyAppName.sqlite")
to the following two lines of code:
let library = NSFileManager.defaultManager().URLsForDirectory(.LibraryDirectory, inDomains: .UserDomainMask)[0] as NSURL
let url = libary.URLByAppendingPathComponent("MyAppName.sqlite")
This would be the syntax for Swift 3 / 4:
let library = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)[0] as NSURL
let url = library.appendingPathComponent("MyAppName.sqlite")
I'm trying to build a quite simple app which uploads files to our server using standard http requests.
I'd like the app to be some sort of hub being able to open an email attachement for example.
That worked out, I added the info to the info.plist.
Now that file is sent to my app successfully (eg a pdf file)...
How can I retrieve that file url to display it for example in a webview ? I googled for hours, seems to fo through the appDelegate but I have no idea how that continues...
Just found this code, now I'm stucked (and don't even know if that actually works !)
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
let dictionary = NSDictionary(contentsOfURL: url)
return true
}
Any help to point me in the right direction is highly appreciated ! I started using swift 5 days ago, please be gentle ;)
I have not tested this, but it appears that what you want to do is this:
Go to your project settings
Go to the "info" tab
Under "Document Types" add the document types you want to support
To get the added file, you need to look in the Documents/Inbox folder for your app, as shown below:
let filemgr = NSFileManager.defaultManager()
let documentsDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
let inboxPath = documentsDirectory.stringByAppendingPathComponent("Inbox")
do {
let dirFiles = try filemgr.contentsOfDirectoryAtPath(inboxPath)
} catch {
//Handle error
}
I am not certain what exactly gets passed to application:openURL:sourceApplication:annotation:, but it might help in checking which file was opened.
Additionally, straight from Apple:
Use this directory to access files that your app was asked to open by outside entities. Specifically, the Mail program places email attachments associated with your app in this directory. Document interaction controllers may also place files in it.
Your app can read and delete files in this directory but cannot create new files or write to existing files. If the user tries to edit a file in this directory, your app must silently move it out of the directory before making any changes.
This answer adapted from this tutorial (part 2 & part 3)
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.
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