How to send sms and call from app? [closed] - ios

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I have situation where On clicking on app icon i have to send sms and
call to a 5 numbers....do we have any third party api's or we have
predefined classes in ios?

regarding the second part of your question "predefined classes in ios"
you can open the device caller or messages app using a url:
func sms(to number: String) {
guard let url = URL(string: "sms:" + number) else {
return
}
UIApplication.shared.openURL(url)
}
func call(_ number: String) {
guard let url = URL(string: "tel://" + number) else {
return
}
UIApplication.shared.openURL(url)
}
example:
sms(to: "12345678901")
call("12345678901")

You can send same message to multiple user at same time using MFMessageComposerView. You can use third party api to message like Nexmo and Twilio.
You can do call once a time. Below is code for call:
NSString *phoneNumber = #"YOUR_CALL_NUMBER";
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];

Related

How to use FirebaseFunctions and log events or errors? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
Since there's only documentation for Node.js, it's unclear of how to use FirebaseFunctions Swift library. I will appreciate if someone can provide some basic examples.
As #jnpdx pointed out in their comment, Firebase only support writing Callable Cloud Functions in Node.js.
What you can do though is call your Cloud Functions from Swift, as shown in the documentation here:
functions.httpsCallable("addMessage").call(["text": inputField.text]) { result, error in
if let error = error as NSError? {
if error.domain == FunctionsErrorDomain {
let code = FunctionsErrorCode(rawValue: error.code)
let message = error.localizedDescription
let details = error.userInfo[FunctionsErrorDetailsKey]
}
// ...
}
if let data = result?.data as? [String: Any], let text = data["text"] as? String {
self.resultField.text = text
}
}
And to handle errors:
if let error = error as NSError? {
if error.domain == FunctionsErrorDomain {
let code = FunctionsErrorCode(rawValue: error.code)
let message = error.localizedDescription
let details = error.userInfo[FunctionsErrorDetailsKey]
}
// ...
}
So it's usually a two-step process:
Write your Cloud Functions in Node.js.
Call them from any of the client side SDKs mentioned in that documentation link
See also the examples in the Firebase Functions Swift QuickStart (thanks to Paul for sharing that link).
See also the examples in the Firebase Functions Swift QuickStart

Which way is recommended to use guard let? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I need to check preconditions for proceeding a function in iOS/Swift.
Option 1:
guard let name = str["name"], let age = str["age"] else {
print("name/age missing")
return
}
Option 2:
guard let name = str["name"] else {
print("name missing")
return
}
guard let age = str["age"] else {
print("age missing")
return
}
Which option is recommended.
This is completely unrelated to Swift.
From a UI / UX perspective certainly the 2nd option since you can now point to the exact input field that is missing.

convert from Swift to Objective C [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to convert this Swift code to Objective C. I searched and did not find a way to convert automatically . Is there any way that can help convert ?
let token="0000000009"
SkyIdConfig.shared.setup(With: token)
var skyIdView:SkyDocumentsAnalyzer?
SkyIdConfig.shared.loadAndConfigure(){[unowned self] isConfigured,error in
if error != nil || !isConfigured {
print(error?.localizedDescription ?? "Error !!!!")
return
}
DispatchQueue.main.async {[unowned self] in
self.skyIdView=SkyIdBuilder.shared.getDocumentAnalyzerInstance(with: "03", lang: "fra")
if self.skyIdView != nil
{
self.skyIdView!.delegate=self
self.skyIdView?.modalPresentationStyle = .fullScreen
self.present(self.skyIdView!, animated: true, completion: nil)
}else{
print("Error in config loading")
}
}
}
Of course there is a way to convert ..
..manually. Which is the best way to understand whats going on.
your token is probably an
NSString *token = #"0000000009";
depending on the Class definition you have to look up how SkyIdConfig is done..
//assuming its something like..
[[SkyIdConfig shared] setupWith:token];
SkyDocumentsAnalyzer *skyIdView = [[SkyDocumentsAnalyzer alloc] init];
[[SkyIdConfig shared] loadAndConfigure];
before going forward in code read more about dispatching in objective-c (aka c) here...

Check how many consecutive days a user has used an app [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I've already seen other questions asking about how many times the app has been opened. I want to send a local notification when the user uses the app for 31 consecutive days.
Would this be a NSUserDefaults discovery method or would I need to use an analytics API?
Use UserDefault. In appdelegate's didFinishLaunch method check for days count
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let kLastUsed = "LastUsedTime"
let kDaysCount = "DaysCount"
let currentDateTimeInterval = Int(Date().timeIntervalSinceReferenceDate)
var storedDaysCount:Int = UserDefaults.standard.integer(forKey: kDaysCount)
if storedDaysCount >= 31 {
//show pushNotifications
}
else {
let lastDateTimeInterval = UserDefaults.standard.integer(forKey: kLastUsed)
let diff = currentDateTimeInterval - lastDateTimeInterval
if diff > 86400 && diff < 172800 {
//next day. increase day count by one
storedDaysCount = storedDaysCount + 1
UserDefaults.standard.set(storedDaysCount, forKey: kDaysCount)
}
else if diff > 86400 {
//not next day. reset counter to 1
UserDefaults.standard.set(1, forKey: kDaysCount)
}
UserDefaults.standard.set(currentDateTimeInterval, forKey: kLastUsed)
}
return true
}
Just expanding on Hitesh's awesome answer to make it more suitable for realtime testing.
You cannot change the date in the simulator settings like you can on a real device. And if you change the date on your real device you might get some Apple server-Xcode syncing issues and Xcode will ask you to register your device in the Developer Portal again.
*Test on a real device using the current time because the UserDefaults needs the date and store from the real device.
To test for minutes or seconds just change all the Ints to Doubles and change the condition to something finer like if storedDaysCount >= 0.0000000015.
let kLastUsed = "LastUsedTime"
let kDaysCount = "DaysCount"
let currentDateTimeInterval = Double(Date().timeIntervalSinceReferenceDate)
var storedDaysCount:Double = UserDefaults.standard.double(forKey: kDaysCount)
if storedDaysCount >= 0.000000000015 {
print("storedDaysCount = \(storedDaysCount)")

Understanding simple code in swift [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I found an answer to implement a link to get rated on the app store (App store link for "rate/review this app"). Answer is:
let appID = "Your App ID on App Store"
let urlStr = "itms-apps://itunes.apple.com/app/id\(appID)" //
(Option 1) Open App Page
let urlStr = "itms-apps://itunes.apple.com/app/viewContentsUserReviews?
id=\(appID)" // (Option 2) Open App Review Tab
if let url = URL(string: urlStr), UIApplication.shared.canOpenURL(url)
{
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler:
nil)
} else {
UIApplication.shared.openURL(url)
}
}
I am having trouble understanding how to implement this. Particularly I don't understand how the if statement will take the user to the app store.
Thanks.
The first part
let appID = "Your App ID on App Store"
let urlStr = "itms-apps://itunes.apple.com/app/id\(appID)" //
(Option 1) Open App Page
let urlStr = "itms-apps://itunes.apple.com/app/viewContentsUserReviews?
id=\(appID)" // (Option 2) Open App Review Tab
gets the url of your app in itunes review section so user can write a review
The second part
if let url = URL(string: urlStr), UIApplication.shared.canOpenURL(url)
checks if the url is valid and can be opened by application.shared if ok it's check the needed function according to the current version.
Actually system know that the app needs to open the url , when it executes the statement , look at open
UIApplication.shared.open(url, options: [:], completionHandler:nil)
Or
UIApplication.shared.openURL(url)
you are opening url with itms-apps:// scheme. So system itself knows what app should handle this.

Resources