KeyChain Set - NoSuchAttribute - Why? - ios

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.

Related

Facebook AccessToken returns nil

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

I am using UUID to get Unique code from iOS Devices but while uninstalling or deleting and re-installing id Changed

I am using UUID to get Unique code from iOS Devices but while uninstalling or deleting and re-installing id Changed..
Suggest Without saving to Keychain and ASIdentifierManager.
let deviceId = (UIDevice.current.identifierForVendor?.uuidString)!
But in android - ANDROID_ID working fine
Note :Keeping the apple privacy and security
You can store UUID in SSKeychain which will be there forever.
See the below code:
class func createUUID() -> String
{
let appName = Bundle.main.infoDictionary![kCFBundleNameKey as String] as! String
var strApplicationUUID = SSKeychain.password(forService: appName, account: "incoding")
if strApplicationUUID == nil {
strApplicationUUID = UIDevice.current.identifierForVendor!.uuidString
SSKeychain.setPassword(strApplicationUUID, forService: appName, account: "incoding")
}
return strApplicationUUID!
}
when app is uninstall and install new app then you get unique code is different that also define in documentation of apple.
you may try
let UUID = NSUUID.UUID().UUIDString
for unique uuid Code.
Addition #sagar's answer which yes UUID is unique for app every install basis. but you may want to use UDID which unique for everydevice. You can check also this
answer from another question. it explains better. It might help.

How to get App name in UITesting swift 4 iOS

I tried to get my app name in UITesting. I tried the code below:
let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
But it gives me the nil value result.
When I was trying to find out if the 'debugDescription' provides any information about the actual app (and not the test app) I stumbled across a label that looked exactly like the app's display name.
I don't know if it helps you, but the following simple line of code helped me:
XCUIApplication().label
Are you sure, that you've set Display name in your Info.plist file?
Just set this name in Project settings or in Info.plist:
Try to go to File > Workspace Settings if you are in a workspace environment or File > Project Settings for a regular project environment.
Then click over the little grey arrow under Derived data section and select your project folder to delete it.
And Product > Clean.
It helps in many situations.
I am getting app name in UI test like this:
let app = XCUIApplication()
// ...
let appName = app.label

Changing Firebase configuration at runtime on iOS

For my project, I have 2 environments:
test
prod
and 2 localizations:
en
tr
and an app for each combination: (these names do not mirror Firebase project ids)
test_en
test_tr
prod_en
prod_tr
And I have a separate plist file for each of these apps in the project, with the names Firebase-(app_type).plist ie Firebase-test_en.plist or Firebase-prod_en.plist
I am initializing FIRApp using this way:
private func ensureLoaded() {
let options = FIROptions(contentsOfFile: Bundle.main
.path(forResource: "Firebase-\(firebaseApplicationName)", ofType: "plist"))!
if nil == FIRApp(named: firebaseApplicationName) {
FIRApp.configure(withName: firebaseApplicationName, options: options)
}
}
And it seems to work ok, until I try to actually connect to firebase database, where it says:
Firebase is not configured correctly, please call [FIRApp configure]
So my question is, how do I make firebase work where I want to dynamically change configurations? There are some other questions that describe how to change configuration based on some environment variables / compiler flags but they are all referring to changing the plist file, which changes the configuration during build time, but I want to change it dynamically during runtime. Is it supported at all, is there a way to make it work?
Thanks in advance.
I found what the problem was, we were using FIRApp.auth().currentUser somewhere in the app, which returns the auth for "default" app and since we had multiple configs, we had no notion of a "default" app, so the configuration was incomplete. I changed that to FIRAuth(app: myApp)?.currentUser and it works as expected now.

How to get bundleId of the source app when using share extension in IOS8

I wanna know which app calls the share extension to share image to my app(its bundleId or appName). But I found no way to do it. There is none information about the source app in NSExtensionContext. I would greatly appreciate any help.
To achieve what you're asking:
#ifdef HIDE_POST_DIALOG
- ( void ) willMoveToParentViewController: ( UIViewController * ) parent
{
// This is called at the point where the Post dialog is about to be shown.
NSString * hostBundleID = [parent valueForKey:(#"_hostBundleID")];
NSLog( #"**** parent bundle id is %#" ,hostBundleID);
}
#endif
You don't get to find out what app is hosting your extension. That's not part of the extension system. You get to find out what kind of data the app is passing you and, with action extensions, you get to return some data. But you don't get to find out who you're dealing with, only what data is going back and forth.
Your bundle ID is usually com.yourcompany/yourname.yourappname
If you don't know what Xcode has for your company name, create a new project and the screen that prompts you for your app name will have your company name.
Also you can do this,
In Xcode, select your project, then your target (you should have only one) and then the 'Info' tab. You should be able to see the bundle identifier there.
The answer to this question can be found here:
How to get bundle ID?

Resources