Sinch: user does not receive the call for the first time - swift

I implemented Sinch + PushKit + CallKit, everything works fine, but there is one script that does not work correctly. The first user uses the application and removes it from the device's memory, the second user calls for the first time, the first user does not receive the call, if the second user immediately calls the second time, the first user receives a call (later the first user also receives a call). If the first user opens the application (that is, becomes online for the system), the first user will not receive the call again. How can I fix it?
initialization of the sinch client
open func setup() {
guard sinch == nil else { return }
guard let userID = UserRealmManager().getUser()?.id else { return }
sinch = Sinch.client(withApplicationKey: key, applicationSecret: secret, environmentHost: host, userId: userID)
sinch?.delegate = self
sinch?.call().delegate = self
sinch?.setSupportCalling(true)
sinch?.enableManagedPushNotifications()
sinch?.setSupportPushNotifications(true)
sinch?.start()
sinch?.startListeningOnActiveConnection()
}
Update: I also found that if I restart the iPhone then calls through CallKit start to show up in 2-4 minutes, I decided to test it on the famous messangers such as What's app and Telegram and they have exactly the same behavior. Of course, I think it needs to be asked as an additional question.
My devices are iPhone 6 and 7.

This was my mistake, since I initialized SinchManager (this is the manager that manages SINClient) only in MainTabBarController viewDidLoad(), after I began to initialize it in AppDelegate didFinishLaunchingWithOptions, everything works fine.

Related

Firebase Phone Authentication for mac catalyst

Context
I am in the process to implement Mac Catalyst in my iOS project. Everything is alright so far except the Google Firebase support.
I am authenticating the user with their phone number. Firebase does this in a two step process. First the device receives a silent push notification & then they are asked to enter their OTP.
The first time I tried, a window opened in safari. It just checked if I am a robot or not. Every other time I tried the window didn't come back.
All this is working with iOS. It just doesn't work on my mac.
Problem
I am getting the following warning:
[Firebase/InstanceID][I-IID003014] Running InstanceID on a simulator doesn't have APNS. Use prod profile by default.
Code
Internet.signIn(with: code) { (error) in
// This line aka the closure is never executed
if error != nil{
alert("Something went wrong", "Try resending the SMS")
return
}
alert("Verified", "Let's continue with entering further user information now") {
self.performSegue(withIdentifier: "userWasVerifiedSegue", sender: self)
}
}
Approaches
I edited my scheme & changed it to "release".
Tried to add a new mac certificate on developer.apple but it doesn't allow me to enter the bundle id.

Firebase Connectivity Test Shows Disconnected At Start Even When Connected. How Do I Change This?

I am trying to make sure Firebase has a connection before continuing to load the app. I'm using the code from Firebase's own code sample. I have placed it in the ViewDidLoad function on my home view controller:
let connectedRef = Database.database().reference(withPath: ".info/connected")
connectedRef.observe(.value, with: { snapshot in
if let connected = snapshot.value as? Bool, connected {
print("Connected")
} else {
print("Not connected")
// show alert here
}
})
The problem is that the above code always shows "Not Connected" before then showing "Connected". This is a problem because when the app is not connected, it's supposed to show an alert, and the alert will then fire every time the user opens the app.
Is this expected behavior? If so, is there a way around it?
How do I check for Firebase connectivity without Firebase returning that it's not connected first every time?
The behavior you're observing is expected. The Firebase SDK can't establish its connection immediately upon startup. There is always going to be some latency between launch and whenever a connection is first available.
Also, I don't think this strategy is a good idea, because mobile connections can be intermittent and flakey. Firebase can not possibly ensure that your app will retain a good connection even after it's first established. Your app will be easier to use if you assume that it doesn't have a connection all the time. Users have come to expect some level of offline usage, and Realtime Database supports that to some degree with offline data persistence.

Which app delegate function to send notifications in background?

I have searched this topic for a while but not found anything that does exactly what I want. I have this code that checks for when a new post is added to the database, and when that happens, I want to send the user a notification. Here is that code:
Database.database().reference().child("\(mySchool!)/posts").observe(.childAdded, with: { (snapshot) in
self.notifyNewPost()
})
My question is, which (if one) function should I put this inside of the app delegate to have this run in the background? Thanks!

Send information to webpage via iPhone app

I´m in the middle of making an order placement app for iPhone using swift.
The app itself is coming along great, but I have a couple of issues I need some help with:
When the user starts the app for the first time, he must make an account with name and address. I can make a basic form for this, but the app must store the information so that the user doesn't´ have to log in every time. How is this done?
When the user presses the "order" button, the order needs to be sent (with name and address from above) to the store´s webpage to be processed.
How is this done?
I hope someone can help me out with this, or point me in the right direction.
Issue number 1 : store the property if user logged in in defaults i.e
#IBAction func loginTapped(_ sender : UIButton) {
if loginSuccssfull{
UserDefaults.standard.set(true , forKey : "loggedIn")
}
}
Then in your first view controllers view did load add following lines
if !UserDefaults.standard.bool(forKey : "loggedIn"){
// present login screen
}
else {
// continue normal
}
Here your are just saving when user logged in and checking if he is already logged in ...
For your second issue you can get help from the following answer on Stackoverflow
HTTP Request in Swift with POST method

Does deleting account from Firebase automatically logs user out?

I would like to know, does deleting account from Firebase automatically logs user out? I mean, if I want to show him after deleting the login screen, then I just have to present that VC? I am asking this because if I do like this, it crashes and I think it is because the user doesn't exists anymore at this points. Am I right?
The code with some explenations :
let user = FIRAuth.auth()?.currentUser
user?.deleteWithCompletion { error in
if let error = error {
// An error happened.
} else {
try! FIRAuth.auth()!.signOut()//This is unnecessary?
let mainStoryboard: UIStoryboard = UIStoryboard(name:"Main",bundle:nil)
let WelcomeViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "WelcomeViewController")
//Send the user to the WelcomeViewController
self.present(WelcomeViewController, animated: true, completion: nil)
// Account deleted.
}
}
If you are deleting your currentUser you need to take care of two things:-
Delete the user's data from the Firebase Database (If there is any)
Delete the auth Credentials (e.g :- email-password, facebook login, twitter etc)
To delete your current user use the below function, which also first sign's out the user
FIRAuth.auth()?.currentUser?.delete(completion: { (err) in
print(err?.localizedDescription)
})
If you CMD+CLICK on the delete function it will take you to its documentation :-
Deletes the user account (also signs out the user, if this was the current user).
completion Optionally; the block invoked when the request to delete the account is complete, or fails. Invoked asynchronously on the main thread in the future.
Possible error codes:
- #c FIRAuthErrorCodeRequiresRecentLogin - Updating email is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.
See #c FIRAuthErrors for a list of error codes that are common to all FIRUser operations.
*/
So long story short if the err received is nil your current users's account has not only been deleted but also signed out automatically, But you will need to handle other FIRAuthErrors as stated in the documentation