2

I hope to make use of existing functionalities in other apps on iOS in my own app. To my knowledge it should be able to be done with URL custom schemes: https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html

Right now in my TryingService gluon application that are acting as a listener, I am using RuntimeArgsService to listen for LAUNCH_URL_KEY. And to my Default-Info.plist file of this application I have added URL Identifier : com.tryingservice.TryingService, and URL Scheme: outputHello. How should I set up my "sender" Gluon application - to open the TryingService application with the URL Scheme?

Right now I am stuck with a functionable URL: enter image description here

lelelo
  • 173
  • 2
  • 12
  • I don't really understand what is your question: Are you asking how to use `RuntimeArgsService` on iOS? Do you want to open _any_ app in your iOS device from a Gluon app? Or do you want to open a Gluon app from a different app (possibly another Gluon app)? – José Pereda Jan 02 '18 at 17:02
  • Lets say I want to open a Gluon apppplication with another Gluon application. How does Gluon application A launch Gluon application B. That is what I am looking for. (I assume the same can be done with any app though - as long as they have registered a url scheme) – lelelo Jan 02 '18 at 17:13
  • 1
    If you want to open a Gluon app you can use `RuntimeArgsService` and register a custom scheme on it. Then you can include a link with an URL with that scheme in another app, and when the user clicks on that link the former app will be opened. Is this what you want? – José Pereda Jan 02 '18 at 17:15
  • I've tested it from a regular HTML page containing that custom URL in an external browser. Possibly the `BrowserService` could be used to launch that URL as well. – José Pereda Jan 02 '18 at 17:46
  • What is the syntax, if URL Identifier is `com.tryingservice.TryingService` and URL Scheme is `outputHello`? I followed this to add them to the `Defualt-Info.plist`: https://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629 – lelelo Jan 03 '18 at 20:28
  • 1
    I think you can use `outputHello://`, and you will get that full URL in the app with `RuntimeArgsService`. – José Pereda Jan 03 '18 at 20:34
  • Yes that worked. I had mistakenly added 2 listeners, one for `LAUNCH_URL_KEY` and one for "outputHello". After removing the faulty "outputHello" listener and typing it as you said`outputHello://com.tryingservice.TryingService` (in my case), a link was created and the exact same URL was recieved in my `TryingService` Gluon application. – lelelo Jan 03 '18 at 21:33
  • How can parameters be sent with URL though? I can't "share" (using `ShareService`) to a specific app - with a destination - without having the user to select app to "open with", and I don't know if `java.net.URLConnection` works? Maybe it is required to use native code - following that link of `Inter-App Communication`?. – lelelo Jan 05 '18 at 18:28
  • 1
    So far, the current implementation of `RunArgsService` only checks for a string, so you could create a URL expression, like `outputHello://com.tryingservice.TryingService?param1=val1&param2=val2`, and then parse it properly. – José Pereda Jan 05 '18 at 18:35
  • I forgot about the `consumer.fire(String key, String value)` method inside `RuntimeArgsService`... Should it be possible to put the `outputHello://com.tryingservice.TryingService` as "key", and the content I want to send with "value"? – lelelo Jan 08 '18 at 16:22
  • 1
    Only if you modify and customize the service. – José Pereda Jan 08 '18 at 16:26
  • Alright. The service already uses `openURL` mentioned in the Apples own guide. So it might not be that difficult. However should it not be possible of writing it in java: https://stackoverflow.com/questions/2406518/why-does-javas-url-class-not-recognize-certain-protocols. When initializing `java.net.URL` I get `java.net.MafomedURlExcption`, and https://stackoverflow.com/questions/26363573/registering-and-using-a-custom-java-net-url-protocol I am expecing the url to be functionable. Hopfully the gluon listening application will respond, but it might be required to use native calls to iOS system – lelelo Jan 08 '18 at 16:40

1 Answers1

1

In the end I made a custom service implementation to ios by following this example: http://docs.gluonhq.com/samples/gonative/

When doing this and after learning some Objective-C I noticed the BrowserService which already had been hinted by José Pereda in the comments to the question - the similarity to my own MyService.m Objective-C file.

After investigating this futher the check in https://bitbucket.org/gluon-oss/charm-down/src/11c36e187921/plugins/plugin-browser/ios/src/main/native/Browser.m?at=default&fileviewer=file-view-default ... if ([[UIApplication sharedApplication] canOpenURL:nsUrl]) - makes it unavailable to launch my custom URL Scheme.

By removing that if- statement in the BrowserService the BrowserService can launch another app that has registered a URL-Scheme. And it does it without launching safari/default browser can be mentioned.

So here is a Gluon app launching another Gluon app (that listens for LAUNCH_URL_KEY with RuntimeArgsService) enter image description here

The correct format also given by José was: outputHello://<your text here>. So I could both leave it empty or adding (a URL to a file for instance) directly after the URL-Scheme part.

However a URL leading to an app's local storage can´t be read from another app due to iOS app Sandbox: What is Sandbox in ios , Can i Trans data between in one App to Another App in iPhone,if possible how

It should be possible to "open url with options" though as suggested here: https://developer.apple.com/documentation/uikit/uiapplicationopenurloptionskey?language=objc.

lelelo
  • 173
  • 2
  • 12