Change call popup to message popup swift - ios

I have this code:
// Get phone number and make a call on tap
if heyObj[HEYS_PHONE] != nil {
if "\(heyObj[HEYS_PHONE])" != "" {
let aURL = URL(string: "telprompt://\(heyObj[HEYS_PHONE]!)")!
if UIApplication.shared.canOpenURL(aURL as URL) {
UIApplication.shared.openURL(aURL)
} else { simpleAlert(mess: "Sorry, Your device cannot make phone calls!") }
} else { simpleAlert(mess: "This user has not provided a phone number") }
} else { simpleAlert(mess: "This user has not provided a phone number") }
}
What this does:
It gets the phone number from a user and make a call on tap.
The popup looks like this:
Is it possible to change this from calling to sending a message?
Is there any function available which can do this?

Related

How to run a function after setupIntentConfirmation succeeds?

I can successfully create and confirm a setupIntent. After the user enters his credit card details and presses the "confirm" button, his payment method is successfully attached to their stripe customer account. However, when the setupIntent is confirmed, I'd like to run a function on my client to send the user to a different screen.
This is where I check the completion of the setupIntentConfirmation. The print statement shows in the console but for some reason, my function is not running.
func onCompletion(status: STPPaymentHandlerActionStatus, si: STPSetupIntent?, error: NSError?) {
self.setupIntentStatus = status
self.error = error
if status == .succeeded {
print("succeeded")
setIsVerifiedToTrue()
}
}
Here is the function I am trying to run:
func setIsVerifiedToTrue() {
let ref = FirebaseReferenceManager.root.collection(FirebaseKeys.CollectionPath.requirements).document(Auth.auth().currentUser!.uid)
ref.updateData([FirebaseKeys.RequirementsFieldPath.verified : true]) { error in
if let error = error {
print("Error updating document: \(error)")
} else {
print("isVerified set to true")
}
}
}
any help would be very much appreciated! :)

Firebase Email Verification Redirect Url

I incorporated Firebase's email verification for my iOS mobile app and am trying to resolve the following issues:
The length of the redirect url appears extremely long. It looks like it repeats itself.
https://app.page.link?link=https://app.firebaseapp.com//auth/action?apiKey%3XXX%26mode%3DverifyEmail%26oobCode%3XXX%26continueUrl%3Dhttps://www.app.com/?verifyemail%253Demail#gmail.com%26lang%3Den&ibi=com.app.app&ifl=https://app.firebaseapp.com//auth/action?apiKey%3XXX%26mode%3DverifyEmail%26oobCode%3XXX%26continueUrl%3Dhttps://www.app.com/?verifyemail%253Demail#gmail.com%26lang%3Den
When I set handleCodeInApp equal to true, and am redirected back to the app when I click on the redirect url, the user's email is not verified. Whereas when I set it to false and go through Firebase's provided web widget, it does get verified. Wasn't able to find documentation that outlined handling the former in swift...
Any thoughts are appreciated.
func sendActivationEmail(_ user: User) {
let actionCodeSettings = ActionCodeSettings.init()
let redirectUrl = String(format: "https://www.app.com/?verifyemail=%#", user.email!)
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.url = URL(string: redirectUrl)
actionCodeSettings.setIOSBundleID("com.app.app")
Auth.auth().currentUser?.sendEmailVerification(with: actionCodeSettings) { error in
guard error == nil else {
AlertController.showAlert(self, title: "Send Error", message: error!.localizedDescription)
return
}
}
}
Make sure you're verifying the oobCode that is part of the callback URL.
Auth.auth().applyActionCode(oobCode!, completion: { (err) in
if err == nil {
// reload the current user
}
})
Once you have done that, try reloading the the user's profile from the server after verifying the email.
Auth.auth().currentUser?.reload(completion: {
(error) in
if(Auth.auth().currentUser?.isEmailVerified)! {
print("email verified")
} else {
print("email NOT verified")
}
})

CloudKit: Get users firstname/surname

I'm trying to get the users first name using cloud kit however the following code is not getting the users first name and is leaving firstNameFromFunction variable empty. Does anyone know how to achieve this in iOS 10?
let container = CKContainer.default()
container.fetchUserRecordID { (recordId, error) in
if error != nil {
print("Handle error)")
}else{
self.container.discoverUserInfo(
withUserRecordID: recordId!, completionHandler: { (userInfo, error) in
if error != nil {
print("Handle error")
}else{
if let userInfo = userInfo {
print("givenName = \(userInfo.displayContact?.givenName)")
print("familyName = \(userInfo.displayContact?.familyName)")
firstNameFromFunction = userInfo.displayContact?.givenName
}else{
print("no user info")
}
}
})
}
}
the permission screen that comes up when asking for the first time, IMO, is very poorly worded. They need to change that. It says "Allow people using 'your app' to look you up by email? People who know your email address will be able to see that you use this app." This make NO sense. This has nothing to do with asking the user to get their iCloud first name, last name, email address.
Speaking of email address - this and the phone number from the lookupInfo property is missing - i.e. set to nil, even though those values are legit and correct. Filing a bug tonight.
First, you will need to request permission to access the user's information.
Then, you can use a CKDiscoverUserIdentitiesOperation. This is just like any other CKOperation (eg. the modify record operation). You just need to create a new operation with the useridentitylookupinfo. Then you will also need to create a completion block to handle the results.
Here is an example function I created:
func getUserName(withRecordID recordID: CKRecordID,
completion: #escaping (String) -> ()) {
if #available(iOS 10.0, *) {
let userInfo = CKUserIdentityLookupInfo(userRecordID: recordID)
let discoverOperation = CKDiscoverUserIdentitiesOperation(userIdentityLookupInfos: [userInfo])
discoverOperation.userIdentityDiscoveredBlock = { (userIdentity, userIdentityLookupInfo) in
let userName = "\((userIdentity.nameComponents?.givenName ?? "")) \((userIdentity.nameComponents?.familyName ?? ""))"
completion(userName)
}
discoverOperation.completionBlock = {
completion("")
}
CKContainer.default().add(discoverOperation)
} else {
// iOS 10 and below version of the code above,
// no longer works. So, we just return an empty string.
completion("")
}
}
First you need to ask the user for permission to be discovered.
Use CKContainer.default().requestApplicationPermission method passing .userDiscoverability on applicationPermission parameter.
The CKContainer.default().discoverUserInfo method is deprecated on iOS 10. Instead use CKContainer.default().discoverUserIdentity method.
Do something like:
CKContainer.default().requestApplicationPermission(.userDiscoverability) { (status, error) in
CKContainer.default().fetchUserRecordID { (record, error) in
CKContainer.default().discoverUserIdentity(withUserRecordID: record!, completionHandler: { (userIdentity, error) in
print("\(userIdentity?.nameComponents?.givenName)")
print("\(userIdentity?.nameComponents?.familyName)")
})
}
}

GKTurnBasedMatch: Unable to get GKLocalPlayerListener delegate methods called on saveCurrentTurn(withMatch .. )?

I'm trying to save match data with the Game Centre default function. The following function works pretty fine and things got saved.
self.myMatch?.saveCurrentTurn(withMatch: dataToSend, completionHandler: { (e) in
print(e ?? "No Error:")
})
This method was introduced in IOS 6, and at that time they were sending push notifications to the opponent as like the endTurnWithNextParticipant, but now in the current IOS 10, if they have removed feature of sending push notifications, but there should any other way to detect matchData update on opponents side.
Yes, the newer way is to use the player listener to detect this kind of change in the match. I have created an example project of a turn based GameKit game that you are welcome to use as a skeleton. The key function is found in the ViewController.swift file:
/// Activates the player's turn.
open func player(_ player: GKPlayer, receivedTurnEventFor match: GKTurnBasedMatch, didBecomeActive: Bool) {
print("***** player received turn event \(didBecomeActive ? "and became active for" : "for") match \(match.shortID)")
dismiss(animated: true, completion: nil)
if didBecomeActive {
// This event activated the application. This means that the user
// tapped on the notification banner and wants to see or play this
// match now.
print("***** attaching the model to this match")
model?.match = match
} else if model?.match?.matchID == match.matchID {
// This is the match the user is currently playing,
// laoding the game model below iwll update to show the latest state
print("***** refreshing data for this match")
} else if match.currentParticipant?.player?.playerID == model?.localPlayerID {
// It became the player's turn in a different match,
// prompt the player to switch to the new match
print("***** ignoring player's turn in match \(match.shortID)")
gameTextView.text.append("\n\nFYI, it is your turn in another match.")
return
} else {
// Something has changed in another match,
// but not sure what.
print("***** ignoring new data for match \(match.shortID)")
gameTextView.text.append("\n\nFYI, something has changed in another match.")
return
}
print("***** loading match")
GameModel.loadGameModel(match: match) { model, error in
guard self.isNotError(error, during: "model loading") else { return }
guard let model = model else {
print("***** no model created")
self.gameLabel.text = "Error setting up game"
self.thereHasBeenAnError = true
return
}
print("***** match load succeeded")
self.model = model
self.model?.checkForWin() { won, error in
guard self.isNotError(error, during: "end match request") else { return }
if won {
self.gameLabel.text = "You won!"
self.turnButton.isEnabled = false
self.resignButton.isEnabled = false
}
}
}
}
The references to the game model will make much more sense in the context of the whole example project, but to your question: notice the "refreshing data for this match" line? That is how you detect new incoming match data. You can do with it whatever you need.

How can I check my entire parse database

In order for somebody to login or signup in my application, you must first enter the email address. If you have an account and enter the correct email address it will then take you to another view controller so you can enter your password. If the email address you enter is not in the database, you will have go to through the setup process. If a user enters the email address JohnnyAppleseed#example.com I need the Done button to check and see if that is in and based on that it will take them to the appropriate view controller.
So my question is, how can I check my parse database for the email the user enters without having to do it by getObjectInBackgroundWithId
Function. Is this possible in Parse?
You could do something like this...
func checkOrXEmail() {
var query = PFQuery(className: "_User")
query.whereKey("email", equalTo: self.emailTextField.text.lowercaseString)
query.findObjectsInBackgroundWithBlock { (emails, error) -> Void in
if let emails = emails {
for email in emails {
if email["email"] as! String == self.emailTextField.text.lowercaseString {
//The email is taken
}
}
}
}
}
Hope this helps!
Also if you want to check the validity of the email try this...
if email.text != "" {
if validateEmail(email.text.lowercaseString) {
emailTaken = false
if self.emailTaken == false {
println("Not Taken")
checkOrXEmail()
}
} else {
// Do stuff
}
} else {
// Do stuff
}

Resources