Get data from unknown website using Webview - ios

I'm currently creating an app where people can book online from a specific website. (The website is NOT owned by me) but is there any way I can get the user input from the website?
My idea is to let a user book from the webpage and their information like name, phone and last name will be saved into my app.
So if a user enter their first and last name on the webpage, I wanna retrieve the input as a string so I can later on create a notification when it's time to attend the booked event. Is there any way to do this?
webview.evaluateJavaScript("document.getElementById('first_3').value") { (data, err) in
if let err = err {
print(err.localizedDescription)
} else {
print("test", data)
}
}
I've added this one to the app, and I found the id "first_3" by viewing the elements.
So, how can I get the user input from a web view into my app?

Related

Swift - get field from randomly created document ID (Firestore)

in my application the user can sign up and by doing that I also save the firstname, lastname and uid.
This is how Firestore-Database looks like:
I would like to access the users lastname but I do not know how, as the Document-ID gets created randomly in the sign-up process.
Auth.auth().createUser(withEmail: email, password: password) { (result, err) in
//check for errors
if let err = err {
self.view.endEditing(true)
self.showError(err.localizedDescription)
}else {
//user was created successfully; store first and last name
let db = Firestore.firestore()
db.collection("users").addDocument(data: ["firstname":firstName, "lastname": lastName, "uid": result!.user.uid]) { (error) in
if error != nil {
self.showError("Error saving user data")
}
}
//transition to home
self.transitionToHome()
}
You need to know one of two things in order to get a document in Firestore:
The full path of the document, including the name of the collection and ID of the document (and any nested subcollections and document IDs)
Something about the data in that document, for example, a value of one of its fields.
If you don't know either of these things, then all you can do is fetch all the documents in a collection and try to figure out what you want by looking at everything in the collection.
The bottom line is that if you don't know which document belongs with which user, you are kind of stuck. You should store the ID of the user in the document, or as the ID of the document itself, so that you can use it to find that document later.
I suggest using the Firebase Auth user ID as the ID of the document. This is extremely common. Don't use addDocument to write it with a random ID, use setData with the ID you know.
Firestore cannot just know which document you want at any time, unless you provide a way for it to locate the document.

Firesbase authentication iOS login get user detail

I have just followed and correctly added the following tutorial to my app. But I’m struggling on how to get the ‘logged in’ users details from the Firestore database?
The Tutorial:
https://youtu.be/1HN7usMROt8
Once the user registers through my app the ‘First name’, ‘last name’ and ‘UID’ are saved by the Firestore database. But once the user logs in how do I GET the users first name to copy to a label on a welcome screen inside the app?
Thanks
I suppose that you know how Firestore works. If you don't you can get all informations in this documentation or watch videos about Firestore on YouTube.
So let's say you have your users saved in collection named users. When the user sign in you can get current user like this:
let currentSignInUser = Auth.auth().currentUser!
If you will force unwrap it make sure that user will be signed in.
When you have current user you can get his uid by calling uid property of current user:
let currentUserID = currentSignInUser.uid
Now you can query this uid to get documents from Firestore users collection that have same UID field value as your current signed in user:
let query = Firestore.firestore().collection("users").whereField("UID", isEqualTo: currentUserID)
Make sure that the first parameter of whereField() function is same as your field name in documents. Because you mention that UID is saved to database I name it UID.
This is all for getting informations of your current user and making query out of it. Now you can GET documents from Firestore:
query.getDocuments() { [weak self] (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
if let userInfo = querySnapshot?.documents.first {
DispatchQueue.main.async {
// Set label text to first name
self?.youLabel.text = userInfo["firstName"]
}
}
}
}
Change userInfo key to whatever name have you used for storing first name in Firestore. For example if you named your document field firstName then userInfo dictionary key must be firstName.

AWS Cognito check and get users

I'm building an iOS App that is using Amazon MobileHub. Currently it's associated with Cognito and the sign up and sign in flow works great.
What I'm trying to achieve is for one user to be able to add another user as a friend so to speak. To make that possible, I need to check if a user with a specific username exists and if it does, get some attributes such as the name of that target user.
I've tried to use the get user > get details function but it gives me an error Authentication delegate not set.
Here's the code I used:
var pool: AWSCognitoIdentityUserPool?
let user = pool?.getUser(usernameField.text!)
self.pool = AWSCognitoIdentityUserPool.init(forKey: AWSCognitoUserPoolsSignInProviderKey)
user?.getDetails().continueWith { (task: AWSTask<AWSCognitoIdentityUserGetDetailsResponse>) -> Any? in
if let error = task.error as NSError? {
print("ERROR: " + error.localizedDescription)
return ""
}
print(task.result)
return ""
}
An approach I thought of was to store the username and the attributes I want to access to DynamoDB and then access it there but that will just create double unnecessary entries.
The issue you'll run into is that user attributes aren't publicly visible. Only the user who has signed in can call GetUser. If it's a back end process, you could do this via the AdminGetUser operation, but this looks client side so I wouldn't recommend that. The only real way around this would be to do what you suggested at the bottom of your post, ultimately.

Slack deep link into client: how to link into im if im not open

I made a platform-independent contactlist-style standalone client for Slack in Qt/C++.
It uses Slack's Deep Linking scheme to navigate through the official Slack-Client when clicking Items in my ContactList.
The problem is, when clicking a user item in my list (which gets the user id and creates the link), the slack client will only enter the im dialog, if it was open before (if i have a im history with that user).
Otherwise it will just show the team directory context for that user, where i manually have to click "message" to actually enter the chat dialog.
Is there really no way to do it right just with slack:// deep links?
The only solution that i can think of right now is to open a new im, if not exist, using api call from my application before opening the link. or maybe open im's for all users at app launch.
But that's kind of a dirty workaround, that i don't like.
Is there a more elegant way to go directly to a new IM than this?
EDIT: quick Workaround without error handling is working this way:
void Window::contactListDoubleClicked(QTableWidgetItem *item)
{
QString id = listWidget->item(item->row(),1)->text();
int type = listWidget->item(item->row(),3)->text().toInt();
if (type == 1) { // if item is a user, we have to ensure that im exists by requesting im.open
QEventLoop eventLoop;
QNetworkAccessManager mgr;
QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QNetworkRequest req(QUrl(QString("https://slack.com/api/im.open?token=").append(m_token).append("&user=").append(id)));
QNetworkReply *reply = mgr.get(req);
// block stack until reply is ready
eventLoop.exec();
qDebug() << reply->readAll();
QDesktopServices::openUrl(QUrl(QString("slack://user?team=XXXXXXXX&id=").append(id),QUrl::TolerantMode));
} else {
QDesktopServices::openUrl(QUrl(QString("slack://channel?team=XXXXXXX&id=").append(id),QUrl::TolerantMode));
}
}

Logout user when deleted from Parse data browser

I have a couple hundred users that I need to remove from my parse app. However, when I delete the user accounts the users are still able to use the app fully without a problem. Is there anyway to "force" the logout remotely? Or what else would you suggest? Thanks!
It sounds like the user is being cached on the device and I don't think parse has a remote way to clear cached data on there. I like to put a user refresh(now fetch since refresh is deprecated) function when app opens to get the latest data for that user.
You could put a fetch function when the app opens and if it returns a specific error, it would mean the user doesn't exist and then set the current user to nil. I'm not sure which error it returns and I'm at work so I can't try it right now. I would hope that if the user doesn't exist, it would return kPFErrorUserWithEmailNotFound = 205...
Here are the error codes: https://parse.com/docs/ios/api/Constants/PFErrorCode.html
You will have to give it a try but I am thinking something like this (sudo-code):
post.fetchIfNeededInBackgroundWithBlock {
(post: PFObject?, error: NSError?) -> Void in
if let someError = error {
if someError = kPFErrorUserWithEmailNotFound {
// User doesn't exist!
}
} else {
// User exists and is fetched successfully
}
}

Resources