For a Proof of Concept, I'd like to be able to make a phone call to a specific phone number and pass data to the telephone number.
Is this possible?
for your first question I'd like to be able to make a phone call to a specific phone number
Ans:
YES, you can do it like
for ex
let phoneNumber = "1234567890"
if let phoneCallURL = NSURL(string: "telprompt://(phoneNumber)") {
let application = UIApplication.sharedApplication()
if application.canOpenURL(phoneCallURL) {
application.openURL(phoneCallURL)
}
else{
println("failed")
}
}
for your second question pass data to the telephone number,
Ans:
NO, it is not possible
but, you can send the data to backend on that call event, and trigger the sms to particular number
Related
// 1
let urlWhats = "https://wa.me/\(mobile)/?text=\(text)"
// 2
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) {
// 3
if let whatsappURL = NSURL(string: urlString) {
// 4
if UIApplication.shared.canOpenURL(whatsappURL as URL) {
// 5
UIApplication.shared.open(whatsappURL as URL, options: [:], completionHandler: nil)
// UIApplication.shared.\
} else {
// 6
print("Cannot Open Whatsapp")
}
}
}
I'm able to launch whatsapp from my app from the above mentioned code, it is composing prefix text to the contact I wish to send and I need to click the send button in whatsapp manually . But I'm looking for a code which automatically sends whatsapp text to number from my app. Can anyone share your thoughts on this?
You can only compose the message for a particular contact using the Deep Linking method that you have used for it. For sending the message user has to click on the send button manually. You could provide the user with an alert that says so. But, it's not possible to do it for the user from your side. If you were able to send a message on Whatsapp by writing code without the user's confirmation it would be a break of user's privacy. Don't you think?
I have this code in Swift 3 to get backendless user so I can get his/her properties:
let whereClause = "objectId = '\(userId)'"
let query = BackendlessDataQuery()
query.whereClause = whereClause
let data = Backendless.sharedInstance().persistenceService.of(BackendlessUser.ofClass())
data?.find(query, response: { (result) in
let user = result?.data.first as! BackendlessUser
myLabel.text = user.getProperty("firstName") as! String
})
The code is working fine but my question is how to observe the property changes ? is there a way if the value of property firstName changed I can update my label automatically ?
The use-case you describe is not really as simple as it may seem, but it's definitely possible.
You can capture any changes in Users table by creating an afterUpdate event handler. From there you could publish a message to some dedicated channel in messaging service.
At the same time, your application should be subscribed to this same channel. This way you could update your UI when the appropriate message is received.
I'm creating a game that uses GameCenter and I'm trying to send and retrieve data.
This is how I'm sending data: (the function 'sendData' is provided by GameCenter with GameKit)
let nick = GCHelper()
let data = NSData(contentsOfFile: "")
try! nick.match.sendData(toAllPlayers: data as! Data, with: .reliable)
'GCHelper' is a class I'm using that contains many functions for Game Center, a download is further through the questions if you're interested. I just needed to call it to access the function.
Then to retrieve data I'm attempting to use this:
nick.match(GKMatch, didReceive: Data, fromPlayer: String)
Note: I have not filled in any of the above parameters
Here is the function I'm using to retrieve the data:
public func match(_ theMatch: GKMatch, didReceive data: Data, fromPlayer playerID: String) {
if match != theMatch {
return
}
delegate?.match(theMatch, didReceiveData: data, fromPlayer: playerID)
}
The function I'm using 'match()' is apart of the GCHelper class. GCHelper allows for you to create GameCenter game easier. Here is a link in case you want to reference it: https://github.com/jackcook/GCHelper
QUESTION
Now that I've showed you all the methods, how would I use the previous method to retrieve data? One of its parameters is 'fromPlayer' and asks for the playerId(String), but how would I know what the other players playerID is? Better yet, how would I retrieve it?
If you don't think this is a good way to handle retrieving data, how could I do it better? Is there another way to do this?
Key Facts:
The game requires 2 people and data is being exchanged between these 2 people only. I need to know how to send and retrieve data amongst the 2.
Thanks for the help! If you have any questions let me know.
This is the function I'm using to retrieve the data:
open func match(_ theMatch: GKMatch, didReceive data: Data, fromPlayer playerID: String) {
}
Now, the data I'm sending is a string. So I create a variable that unarchives the data and sets it to string format.
let myString = NSKeyedUnarchiver.unarchiveObject(with: data) as! String
After this, I need a way to get that string from the view controller or game center file to my game scene. In which I simply just stored the data using UserDefaults.
let user = UserDefaults.standard
user.set(myString, forKey: "myString")
Then in my SKScene I created a timer, in which it checks every couple of seconds to see if there's a change. It stores the values so that when a new values arrives it can compare and if it is different it does something with it, for example: update player points.
Note: This is what I found to work, someone else may have a better way, but it works fine for me.
I have an NSURL being returned to me as something like
tel:555-555-5555
I can recognize it as a telephone by identifying the NSURL's scheme as "tel" using
let url = NSURL(string: "tel:555-555-5555")
if url.scheme == "tel" {
// it's a telephone number
}
But I can't find a command to get the actual phone number component. The phone numbers can come back much more messy than the example I gave, so I thought it would be much safer to ask if there was a way to get the phone number component directly instead of saving as string and clipping out the scheme.
Use resourceSpecifier:
let url = NSURL(string: "tel:555-555-5555")!
if url.scheme == "tel" {
let number = url.resourceSpecifier
}
I'm trying to develop an iPhone app and implementing a functionality similar to snapchat's and so many other apps. I want to ask for the user's mobile phone number and add it to my database. I then want to ask for permission to access my address book and based on my mobile phone contacts (friends mobile number) I can suggest the profiles of my friends who have installed the app. I developed some functions in which I was able to get all the user's contacts as a string. But I have some issues. People can write the mobile numbers in different ways (putting the country code in first place, etc). Since I am matching an exact string it becomes kind of hard.
Is there any solution for this problem? I know that different countries have different ways of writing the mobile numbers.
F.e. in Portugal we can write 00351 911 111 111 or +351 911 111 111 or 911 111 111 . This will be easy to solve in Portugal since we all have the last 9 digits and it is easy to compare. But in the US I have seen (555) XXX-XXXX or XXX-XXX-XXXX and many other formats.. I can't determine how the user has saved the contact and the same with other countries.
ALL HAPPENS AFTER ASKING FOR AN AUTHORIZATION
In the viewDidLoad I search in Parse the users of my mobile phone
override func viewDidAppear(animated: Bool) {
var query = PFUser.query()
query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let users = objects {
self.contactsUsernameArray.removeAll(keepCapacity: false)
self.contactsNameArray.removeAll(keepCapacity: false)
self.contactsImageFiles.removeAll(keepCapacity: false)
self.contactsNumberArray.removeAll(keepCapacity: false)
for object in users {
for var i = 0; i < self.phoneNumbers.count - 1; i++ {
if object["phoneNumber"] as! String == self.phoneNumbers[i] {
self.contactsUsernameArray.append(object.username!!)
self.contactsNameArray.append(object["name"] as! String)
self.contactsNumberArray.append(object["phoneNumber"] as! String)
self.contactsImageFiles.append(object["photo"] as! PFFile)
}
}
}
}
//println(self.usernames)
//println(self.userids)
self.contactsTable.reloadData()
})
}
You can try phone numbers format E.164
E.164