How do I make my SwiftUI app open from a string? - swiftui

It's possible to use "openURL(...)" on a View so that the system opens my SwiftUI app with a URL passed in for processing. That happens when, for example, I drag a suitable object and drop it on my app icon or open app. I want to do the same thing with my object that's represented as a String (JSON in this case). What do I call to do this, i.e., is there something like "openString(...)"?
There are a number of view modifiers like "onCommand", "onPasteCommand", etc. that sort of look like they might work but I'm missing some an overview of what the right options are to make my app respond properly to events that communicate data. Also, I'm looking for the preferred way to do this for iOS 14.

What did work for me was to use ".onOpenURL" and read the data from the URL there. To export data, create a UIActivityItemProvider that writes the data to a file in the app's tmp directory and returns its URL. These two actions can be used with the UIActivityViewController to share.

Related

Get the window title data from a SwiftUI document based app

Setting up a SwiftUI life cycle document based app is easy, especially for the title part -- it helps me handle all the file work I needed such as monitoring file name changes/move/deletion/editing status. However I want to hide it and create my own title, but I still want to take the advantage of these data. Is there a way that I can get them (file name, URL, edited status, etc) from somewhere? I tried to look for it in the FileDocument but it seems to be limited.
Thanks!

Is there a keyboard shortcut in Postman to get to the Body of a request?

After clicking on a saved request in Postman, I get a view that looks like this:
To view the body, I need to click "Body".
This is not a big deal, except if I am doing this with 20 or so requests, looking for something particular in the body of each one, it would be a much nicer work-flow to be able to use a keyboard shortcut to reach that section.
Does anybody know of such a shortcut, or alternative way to do this?
Thanks!
You can check out available shortcuts from the App's settings (Wrench icon on the right > Settings > Shortcuts tab). At this point I don't think there's a way to do what you're asking.
However, as an alternative...
You could export the collection, edit the json directly in your favourite text editor and then import the collection back in. If you have to do a global find/replace this can be a huge time saver.

Ionic 2 - Store user credentials (local storage vs nav params)

I´m developing an Ionic 2 app. When I make login, I could store user credentials on SQLStorage, LocalStorage or transfer it as parameter on NavParam.
Example:
onLogin(){
this.nav.setRoot(MainPageComponent,user);
}
vs
let storage = new Storage(SqlStorage);
storage.set('name', 'Max');
What is the main advantage of storage over passing as parameter?
What is the main advantage of storage over passing as parameter?
If you use that information just in one page or two, you can send it as parameter. But the problem is that you will probably use the name in more than one place (maybe in a settings page, or in the side menu of the app, and so on), so storing that information somewhere would be a good idea so you can get it back when you need to.
Also, if you get that information in one page, and you want to show it in another one, but those pages are not connected directly in the workflow of your app, you would need to pass it through some other pages just to get it where you want to show it. So again, storing that data seems to be a better approach.
Please notice that if you use SQLStorage or LocalStorage, you should set also an expiration date to force the user to log in again after a given period of time.
Navparams is used for transferring the data between pages say, you have to open a particular item's details, you need to click on an Item and the parameters will be sent using Navprams to the itemDescription page.
You prefer localstorage.setItem('userId', $userId), because storing locally will solve the unwanted sign-in every time you open the app.
If you store in your local storage, then on every app on load, we can check the existence of the local variable.
if(localstorage.getItem('userId')==null){
this.signin();
}
else{
this.appOpen();
}
This one can help you!

Webview Swipe issue - Appcelerator Titanium

Right now I am using one webview to show data from my aplicationDatadirectory, here everything is working fine, I get content when user click next back respectively. Now what I am doing is in onload of webview I register "touchevent" and "touchmove" in webview's html like this :-
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchstart", function mytouch(){Ti.App.fireEvent("touch", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchmove", function mymove(){Ti.App.fireEvent("move", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
on the basis of this I find swipe event. I get correct html in webview(I can see images). But I am unable to get touchstart and move call. I dont know what is the problem here. I set data in webview using url here.
Now when I set data in webview using html(I used data of my html file(given below) in one var) now I am unable to see images it just shows me one black border(empty) but here my touchstart and touchmove events are firing also my swipe is also working as expected. I am checking this functionality in iPhone.
Can any one find the issue what is going wrong here? Thanks.
I think that this depends on the time when you apply
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchstart", function mytouch(){Ti.App.fireEvent("touch", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchmove", function mymove(){Ti.App.fireEvent("move", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
If you use the html property data is loaded immediately and you can use the code exactly after setting html content. If you use the url (even if it is located locally, which might be difficult for android) then you need to wait a short time until the page is loaded. There is also an event listener for that (web view-event load) but i can't say if that works for local resources but i don't think so.
In this case you should apply your javascript snippet into your html resources (if they are locally) instead of manually adding it using evalJS.
Please note that there is an issue on android that you can't use local images (resources folder) in your webview when you provide the content via html property.
I made it swipe working in iOS(in android it was working).
I did not expect this thing to be a reason but I do not know logic behind it. I was accessing .xhtml files from application data directory and it was working without any issue in android but in iOS it was not.
I just change(rename in my code) .xhtml file to .html and now it is working. :)
Hope this can help someone who is looking for the same.(or just for his interest)
Thanks.

Saving user's data for my application

I was wondering what would be the correct method for saving all user data for an application I am working on. The application is in QT. The user inputs a lot of data into the application and the data will be different for every user. I want the ability for the user to save all the current data to a file that can be user by the loaded by the application again once the user wants to use it again or use it on another computer running the application.
What would be the correct and best way to do this? Do I need to use xml format? And then use the xmlreader for QT? Or do I just need to create my own file format and just use the stream to just read everything in. The data in the file will need to be labeled, because it will need to put the data in certain spots on the gui. And the user has the option to dynamically create boxes and tabs that hold certain information.
If you need any more information, please let me know.
A short example:
I am not only reading gui locations.
But the contents of those. For
instance. The user is able to create
tabs that contain edit text boxes. And
those tabs are associated with items
that are in a list. When the user
clicks on an item in the list the user
will be presented with a whole set of
new tabs. And each tab has some
editing forms. The file will need to
contain what is in the list, what tabs
the user has created under each item
in that list and the contents of each
tab associated with the tab of each
item in the list.
In essense, yes you'll be creating your own file format, but the actual content can just be XML in whatever scheme you need. Then you can use Qt's built-in XML processing capabilities to pull the heavy lifting of parsing the text (I personally prefer the DOM model, so I use QDomDocument as my base point), and you'll just need to worry about parsing things to and from the individual nodes.
The Qt framework has some great XML samples if I remember correctly that helped me get off the ground almost immediately. Hope they help!
Another great solution is to use internal database implementation (QSQL on top of sqlite). Compared to the xml solution, it might be more versatile (update when needed, can use external keys). Qt has some rgeat examples about using it aas well.
In terms of dependencies, XML solution will require you to use xml and xmlpatterns (if you want to validate stuff), whereas sqlite solution will require QSQL + sqlite plugin. I think that sqlite guarantees atomicity of writing , thus preventing corruption of data (think : the user is killing the app while it's saving).