Facebook AccessToken returns nil - ios

I can no longer sign-in-with-Facebook inside my app as AcessToken return nil...
Here is my function:
let accessToken = AccessToken.current
guard let accessTokenString = accessToken?.tokenString else {
print("bruh")
return
}
It currently prints the "bruh".
It was working the other days!
I didn't change anything inside that file. But I changed the Project Name and the Bundle Identifier. Could this have anything to do with the error?
UPDATE: I deleted the old Facebook-Project and created a new one with the correct Bundle-ID. I also changed the ID and Secret Token inside Firebase.
Is there anything else I need to do??? really annoying ...
Is there maybe a way to show an error to see what the actual problem is?

It seems to be about changing of Bundle Identifier,
You should set the new one on https://developers.facebook.com/

I fixed the issue! The problem was that I had the old ID inside my info.plist

Related

KeyChain Set - NoSuchAttribute - Why?

Here's my code:
static void SetA(byte[] b)
{
var result = SecKeyChain.Add(new SecRecord(SecKind.Key) { Generic = "test", ValueData = NSData.FromArray(b) });
Debug.WriteLine(result);
}
result is:
NoSuchAttribute
Is it because I'm debugging and when I publish it it'll work?
Is it because I need to add something to info.plist?
Is it because I need to specify something in the provisioning
profile?
Or is it because I'm missing some step in the code?
...
This is my first attempt at using KeyChain, so please don't discount (as in "disregard") any simple mistake I may have made.
I was having the exact same error. I was following the official samples from here
https://github.com/xamarin/ios-samples/tree/master/Keychain.
I debugged it and found out that the Error NoSuchAttribute comes from the Generic attribute. In the official Apple documentation the kSecAttrGeneric attribute is listed under "Password Attributes". So I assume the xamarin example is correct because it uses SecKind.GenericPassword.
Replace Generic by Label or something else to identify your keychain record.
To use your code
static void SetA(byte[] b)
{
var result = SecKeyChain.Add(new SecRecord(SecKind.Key) {
Label = "test",
ValueData = NSData.FromArray(b)
});
Debug.WriteLine(result);
}
Is it because I'm debugging and when I publish it it'll work?
No , Keychain works in debug/release mode.
Is it because I need to add something to info.plist?
No need.
Is it because I need to specify something in the provisioning profile?
No need
Or is it because I'm missing some step in the code?
You need set keychain-access-groups(bundle identifier) in Entitlements.plist , then in the App's iOS Bundle Signing, ensure that the Custom Entitlements is set to Entitlements.plist .
keychain directly depepds on Bundle id , if bundle id remain same then your app can acess keychain , so provisioning profile should map the same bundle id if app needs to acccess keychain.
At last ,check the offical sample for keychain : https://github.com/xamarin/ios-samples/tree/master/Keychain.

Firebase's snapshot.value cast to Bool suddenly returning nil

So my code was working perfectly fine but today it is returning nil when I try to cast Firebase's snapshot.value to a Bool. I haven't made any change to code at all. But it works fine if I cast it to a String (as? String returns "true").
Same issue at another place where I was casting to [String: Bool].
One thing that is different from earlier, I installed Xcode 10 beta 3 today (Xcode 9.4 is installed too). Both Xcode versions are returning nil. Here's the code:
if let currentUserId = Auth.auth().currentUser?.uid{
Database.database().reference().child("users/\(currentUserId)/share").observe(.childAdded) { (snapshot) in
let data = snapshot.value as? Bool
if data == true{
self.showNotificationsBadge()
}
}
}
Edit: Snapshot is not nil. You can see that in the console pane. I have printed both snapshot.key and .value.
Edit 2: I'm sorry if my question caused any confusions. The main purpose of this question is to know the problem, is it Firebase SDK or Xcode. Because it was working perfectly till now. I know how I can tackle this and how can I convert a String to a Bool.
Edit 3: Thank you everyone for your answers. I'm sorry I was unable to deliver my thoughts correctly. I just want to know about this unpredicted behavior and why is it happening? Who is the culprit here? Xcode, Firebase SDK? This code worked PERFECTLY FINE for about a month. I'm not asking for a solution, I'm just curious about this behavior. It would be great if someone from team Firebase can explain this issue.
Edit 4: Removed image and added code. Also figured out the issue thanks to #Jay's comment.
You need check if the snapshot is nil before checking the value.
if let data = snapshot.value as? Bool {
....
}
This happened to me just recently. I discovered that I had quotes around the child value, eg. "true". Remove the quotes and the solution from #Maximo should work as expected.

How can I open a pdf link when click a button on Swift?

I am trying to open a pdf from my Swift application but I cannot make it to work.
I know that there are a lot of questions related with this and in most of them they use this code:
UIApplication.shared.openURL(URL(string: "http://www.url.com" + id)!)
But I am getting the following error:
fatal error: unexpectedly found nil while unwrapping an Optional value
so I thought that the error was because the id was nil so I made two prints to see what was retrieved: one for url and one for id. Both of them are correct and if I copy the url on the browser navigation bar it works perfectly (I cannot provide the real url because it is of a client).
I have this function wrapped inside an #IBAction to detect when a button is clicked so I looked if the connection had been broken. It is also correct.
So I cannot understand why this error is happening. I spent some hours but cannot figure out what is causing this error.
Am I missing something? Should I codify the url in some way?
P.S: I am using Xcode8 and Swift3.
UPDATE: If I set www.google.es it is working perfectly. Can it be a problem using variables inside of the url?
Thanks in advance!
Finally, after some hours searching about the problem and following the recommendation of #rmaddy (Thanks!) I have split my function in three parts and I could see that the URL was returning nil value.
It was strange because I could copy the string into my browser navigation bar and it worked well so I thought that it could be something about encoding. One time I have encoded it I noticed that the id of the pdf was retrieved with a \r at the final of the id. Like this:
id004.pdf\r
The solution that I have done is the following:
var string = "http://www.url.com" + id
var index1 = string.index(string.endIndex, offsetBy: -1)
var substring1 = string.substring(to: index1)
let encodedString = substring1.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
UIApplication.shared.openURL(NSURL(string: encodedString!) as! URL)
Encoded string is necessary because if not the link no longer work.

Firebase is referencing an old project and not the current one

In my new project, I am making sure that users do not have to go to the login screen every time they open the app by using the following code:
// this means that there is a user logged in... take them to the main view.
if let x = FIRAuth.auth()?.currentUser?.uid {
print("The current user is: \(x)")
// first param is storyboard name
self.setTheRootViewController("Main", identifier: "GroupChatsView")
}
// take them to the login view controller
else {
self.setTheRootViewController("Main", identifier: "LoginView")
}
I have not created any users yet, so I would expect this code to take me to the login view every time. But, For some odd reason, when I print out the current user's unique id, it is my own unique id from a previous project. I am not sure what to do at this point. Also, everything in my GoogleService-Info.plist matches up with my new project.
When I logout of my other app in the iOS simulator, the code functions as expected.
Are there any easy workarounds for this? Thanks.
In your simulator clean and reset settings ! It does the trick.

iOS Realm readOnly causes empty result

I have a little problem with realm setting readOnly to true in the configuration. I am using Swift but I am using the normal Realm.framework ... Maybe this causes the error but I don't think so. (I am using it because I don't want to refactor my whole code...)
Here is an example of what I am talking about.
I tried this:
if let path = NSBundle.mainBundle().pathForResource("database", ofType: "realm")
{
//Alternative: or move the file from the app bundle into a writable location
var config = RLMRealmConfiguration()
config.path = path
config.readOnly = true
do {
try self.realm = RLMRealm(configuration:config)
} catch {
print("ERROR")
}
I also tried this:
if let path = NSBundle.mainBundle().pathForResource("database", ofType: "realm")
{
//Alternative: or move the file from the app bundle into a writable location
var config = RLMRealmConfiguration()
config.path = path
config.readOnly = true
RLMRealmConfiguration.setDefaultConfiguration(config)
do {
try self.realm = RLMRealm(configuration: RLMRealmConfiguration.defaultConfiguration())
} catch {
print("ERROR")
}
Both of them fail every time. (Printing: "Error") I figured out that the problem is that readOnly is set to true. I got both snippets working by setting readOnly to false.
Do you have any idea how to fix this issue?
I printed the Error and it is:
Error Domain=io.realm Code=2 "Unable to open a realm at path
'/Users/UserName/Library/Developer/CoreSimulator/Devices/NR/data/Containers/Bundle/Application/NR/AppName.app/database.realm'"
UserInfo={NSFilePath=/Users/UserName/Library/Developer/CoreSimulator/Devices/NR/data/Containers/Bundle/Application/NR/AppName.app/database.realm,
NSLocalizedDescription=Unable to open a realm at path
'/Users/UserName/Library/Developer/CoreSimulator/Devices/NR/data/Containers/Bundle/Application/NR/AppName.app/database.realm',
Error Code=2}
Okay guys I have no idea what happened but it works now.
I made a sample project with the database of their database and an object for their database and tried my code and it worked. (Both of them)
This confused me pretty much and I thought maybe my database is damaged or the object is wrong. I replaced their database in the sample project with my database and used my object and surprise it worked...
So I just deleted my database in my normal project (as I did 1000 times before) and added it again. I just put it on the top of my project structure and tried it again and it is working now...

Resources