Forum Xamarin.iOS

Will Apple reject my app for storing the IdentifierForVendor?

Billy12ShovelsBilly12Shovels USUniversity ✭✭✭

Hello Forums,

I am storing the IdentifierForVendor to consistently identify devices for authentication (credit for method to https://haknode.wordpress.com/2016/08/30/xamarin-get-a-unique-device-id/):

/*
 * The value of CurrentDevice.IdentifierForVendor changes if the app is removed and reinstalled.
 * Therefore some ID (the value of IdentifierForVendor) is stored to the keychain and
 * reused every time (even after a reinstall). See http://stackoverflow.com/a/22937460
 */

String id;

String ServiceId = "KeyChainAccountStore";

//use the bundle identifier of the app to identifie the value in the keychain
String appId = NSBundle.MainBundle.InfoDictionary["CFBundleIdentifier"].ToString();

//Try to read the id from the keychain
var rec = new SecRecord(SecKind.GenericPassword)
{
    Service = ServiceId,
    Account = appId,
};

SecStatusCode res;
var match = SecKeyChain.QueryAsRecord(rec, out res);

//Store a new ID to the keychain
if (match?.Generic == null)
{
    //Get the vendor ID (does change after a reinstall of the app)
    var vendorId = UIKit.UIDevice.CurrentDevice.IdentifierForVendor.AsString().Replace("-", "");

    SecRecord record = new SecRecord(SecKind.GenericPassword)
    {
        Service = ServiceId,
        Account = appId,
        Generic = NSData.FromString(vendorId),
        Accessible = SecAccessible.Always
    };

    var statusCode = SecKeyChain.Add(record);

    if(statusCode != SecStatusCode.Success)
        Debug.WriteLine("Could not save key to KeyChain: " + statusCode);

    id = vendorId;
}
else
{   //Use ID from keychain
    id = match.Generic.ToString();
}

return id;

Will Apple reject my application for doing this?

Thanks!

Tagged:

Best Answer

Answers

  • @CodyRousseau I'm trying a similar approach. I'm interested to know what apple support told you. Also, were you able to build without any errors? I've enabled Entitlements as described here, but I keep getting this error error
    MT1006: Could not install the application on the device : Your code signing/provisioning profiles are not correctly configured. Probably you have an entitlement not supported by your current provisioning profile, or your device is not part of the current provisioning profile. Please check the iOS Device Log for details (error: 0xe8008016).

  • Billy12ShovelsBilly12Shovels USUniversity ✭✭✭

    I do believe apple never got back to me, and I have not attempted to publish an app with this functionality yet.

    @madhav.shenoy83
    Your error is with your provisioning profile not having the device you are trying to deploy to associated with it. You need to go to the apple developer portal and configure your profile with your device.

Sign In or Register to comment.