Suppose I am making a server call using NSURLRequest and NSURLConnection. I am making call to URL such as "http://www.testAAA.com.au/methodName". Now user installed my App. Few days later, I needed to change base URL. For example: "http://www.testAAA.com.au" to "http://www.testBBB.com.au".
In short, just base URL is being modified. I need to set such a mechanism that once server base URL changes, App can update base URL in the next call made for device. I have taken a constant for base url. So, next time the App makes any call to old base URL, I need to update that base URL with new one.
Is there any trick I can use?
Suppose you have const NSString *baseURL; in your Constants.h file, then in didFinishLaunchingWithOptions you can set your baseURL with the new one, this will update the url when user restart the app.
A common practise is to have a remote config endpoint that supplies a config file of some flavour (plist/json/whatever) that is downloaded at application launch.
Launch app.
Download remote config file.
Configure app with remote config.
Enjoy soft endpoint configuration.
It does rely on you having a constant config endpoint for any given app version but does mean you can change API endpoints at will.
Related
I'm trying to register a custom protocol with electron. I want it to be a redirect location that a website can use to provide an api key (like myprotocol://example/payload=api-key). I have been using electron's registerHttpProtocol and also tried electron's interceptHttpProtocol.
But, when the website tries to redirect to my protocol my electron app doesn't do anything. The website goes to myprotocol://example/payload=api-key, and registers a "page doesn't exist error"--while nothing happens in my app.
This is in a development environment. I've seen some discussion about custom protocols that assume a production environment.
Can you register a custom protocol with electron in development?
Why am I not able to intercept the website's going to the protocol I've set out?
Here's my code:
main.js:
app.whenReady().then(() => {
protocol.registerHttpProtocol('examplep', (request, callback) => {
console.log("examplep", request);
callback('it-worked');
}, (error) => {
if (error) console.error('Failed to register protocol = ' + error)
})
protocol.interceptHttpProtocol("examplep", function (request, callback) { //I've tried both registerHttp... and interceptHttp... methods, so including both here; though I think in practice only one should be required
console.log('intercepted!' + request)
callback(request);
});
})
redirect url provided to website:
'http://examplep'
And I've whitelisted this url on the website itself.
I've also tried related methods registerStringProtocol, interceptStringProtocol, registerFileProtocol, and interceptFileProtocol, without success.
What am I missing?
Sounds like you need to support deep linking fora desktop app, which is done via a Custom URI Scheme and is registered with setAsDefaultProtocolClient.
When your Electron app starts up write this code to register the scheme, on the main side of your app:
const customScheme = 'x-mycompany-myapp';
app.setAsDefaultProtocolClient(customScheme);
The custom scheme can be tested from the command line like this, depending whether you are running macOS or Windows:
open x-mycompany-myapp:/some/location
start x-mycompany-myapp:/some/location
A web client will just invoke a URL as in this Javascript code of mine;
The notification will be received within the main side of your app and on Windows will attempt to create a new instance of the app, in which case you need to detect this condition, process the notification then cancel the new app instance.
On MacOS it will be received within the open-url event, so you register it like this:
app.on('open-url', this._onOpenUrl);
Once the main side of the Electron app has the notification, it needs to get the URL information and forward it to the renderer process. You can use ipcMain events for this.
Finally the code for receiving the notification in running instances and starting the app from a deep link are different.
EXAMPLE APP
Since the code is a little tricky, here is some example code that may be useful, to give you something to compare against. If it helps you can also run the app by following the instructions in the blog post:
Code
Blog Post
My use case is around receiving OAuth responses after signing in from the system browser. Hopefully you can borrow some ideas from it related to deep linking though.
INFO.PLIST
My understand is that in a development environment (on macOS) deep links work when the app is running, but if you stop the app and attempt a deep link it will not start the app.
You can only resolve this for a packaged app, which requires an info.plist. In my code sample the info.plist is generated from build protocol entries in the package.json file.
My code sample is packaged in a basic way by the Electron Packager, so when I run npm run pack, the app is built to a dist folder. I can then run the packaged version of the app and it gets registered with the system - as can be seen in the Default Apps tool. See screenshots in the blog post.
SECRETS
Secrets for a desktop app should be stored using operating system secure storage. There are screenshots of credential storage in the blog post.
On Electron, have a look at the keytar component - and this wrapper class of mine. I am storing tokens (strings) so you should be able to adapt the code for your API keys.
I'm very confused. I want to store few user files, but not docs. I'm using:
static var directory: URL {
get {
return FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)[0].appendingPathComponent("Caches").appendingPathComponent("OnlineFiles")
}
}
Always the same. Every time I launch the app I get different URL.
Am I doing something wrong? Is there some magic switch in project file which I need to set?
Once it's something like:
file:///var/mobile/Containers/Data/Application/4547EF22-EB33-4B65-9772-67ED7870E3E9/Library/Caches/OnlineFiles
Other time it's:
file:///var/mobile/Containers/Data/Application/83C8CDD7-B4D0-48B2-8A8E-9BD48C5D1754/Library/Caches/OnlineFiles
This string between /Application/ and /Library/ seems to be random. How to store files in one location when I can access them later when opening app second time?
[EDIT]: how to get path which is not changed every time I update app?
This is apple's security mechanism.Every time you restart the APP, apple sandbox path of APP to encryption, to prevent access to other programs.The encryption keys inside the APP.So before the end of the program, no matter where to access the APP sandbox, return to the path are the same.If you want to know more, you can look at apple's sandbox mechanism.
I am trying setup iOS universal link with a private server. I put my apple-app-site-association on my private_domain/apple-app-site-association .
However, iOS can not download the Apple-app-site-association from server even testing device in the same network as my private domain . I am wondering if it possible to set up Universal Link with Private Domain ? Thanks
This is not possible, no. You'll see in the device logs, if you watch during app installation, that setup of universal links is failing because the domain cannot be reached.
You can work around this by creating a public domain (just use an Azure site or something similar). The apple-app-site-association must exist as a static file. Note that if you are using Azure you'll need to add a file handler for the empty file extension and another file handler for Android's json file extension if you're doing Android as well.
If you want the links to work for web as well then just have the paths redirect to your internal (private) domain.
I know it's possible to pass data from one app to another app on the same device using custom url schemes or protocol handlers.
Is it possible to pass data from one app to another app that isn't installed? Ideally the user would be taken to the app store for the uninstalled app, the user would download the uninstalled app, and the custom url scheme from the original app would still pass the data to the newly installed app.
Is that possible?
Is it possible to pass data from one app to another app that isn't
installed?
YES.
using the x-callback parameters, we can ask the target app to call us back on our own URLs, even handling success and error scenarios.Sort of like custom HTTP headers, these callback parameters are identified with an x- namespace:
x-error : URL to open if the requested action generates an error in the target app. This URL will be open with at least the parameters “errorCode=code&errorMessage=message. If x-error is not present, and a error occurs, it is assumed the target app will report the failure to the user and remain in the target app.
x-source : The friendly name of the source app calling the action.
x-success : If the action in the target method is intended to return a result to the source app, the x-callback parameter should be included and provide a URL to open to return to the source app. On completion of the action, the target app will open this URL, possibly with additional parameters tacked on to return a result to the source app. If x-success is not provided, it is assumed that the user will stay in the target app on successful completion of the action.
I´m downloading a file to a SD card in the BlackBerry, and when I open that file, my application run. So when my application run, I need to delete that file.
The problem is that I dont know where it is(the file) from my app, because the user could download that file anywhere.
Is there something in the BB OS that let me know the path of that file? With this I can give to my app a parameter or something...
Well, thats it.
If you register with invocation registry so that your app is invoked whenever file needs to be opened, you will get full URL in Invocation object. This URL is sufficient to delete the file via FileConnector.
See this BlackBerry example to properly register your app. Also, in step 6 note invoc.getURL() - this is what you need to use.