Always get a unique device id in iOS 7

后端 未结 7 2242
予麋鹿
予麋鹿 2020-12-12 17:36

Our iOS application is for specific users. So, we used device unique identifier for user identification. This approach works fine till iOS 6, because we are

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 18:03

    Use this little helper method to keep identifier in Keychain between install/delete sessions of app

    -(NSString *)getUniqueDeviceIdentifierAsString
    {
        NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];
    
        NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"];
        if (strApplicationUUID == nil)
        {
            strApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
            [SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"];
        }
    
        return strApplicationUUID;
    }
    

    Add the SSKeychain library to your project, e.g. via Cocoapods with pod 'SSKeychain'

提交回复
热议问题