Giter Site home page Giter Site logo

fabiocaccamo / fcuuid Goto Github PK

View Code? Open in Web Editor NEW
1.6K 56.0 221.0 64 KB

:iphone: :id: iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor.

License: MIT License

Objective-C 91.42% Ruby 4.22% Swift 4.36%
uuid udid persistence device unique-identifier ios objective-c uuids pod session

fcuuid's Introduction

FCUUID Pod version Pod platforms Pod license

iOS UUID library as alternative to the old good UDID and identifierForVendor. This library provides the simplest API to obtain universally unique identifiers with different levels of persistence.

It's possible to retrieve the UUIDs created for all devices of the same user, in this way with a little bit of server-side help it's possible manage guest accounts across multiple devices easily.

Requirements & dependencies

  • iOS >= 5.0
  • ARC enabled
  • Key-value storage enabled (target / Capabilities / iCloud / Key-value storage)
  • Security.framework
  • UICKeyChainStore
  • (optional) - Key-value storage enabled -> Target / Capabilities / iCloud / Key-value storage enabled if you want to share uuidsOfUserDevices values across multiple devices using the same iCloud account.
  • (optional) - KeyChain sharing enabled (entitlements and provisioning profile) if you need to share the same uuidForDevice / uuidsOfUserDevices values across multiple apps with the same bundle seed.

Installation

CocoaPods:

pod 'FCUUID'

  1. File > Swift Packages > Add Package Dependency
  2. Add https://github.com/fabiocaccamo/FCUUID
  3. Select "Up to Next Major" with "1.0.0"
github "fabiocaccamo/FCUUID"

Manual install:

Optional setup:

It is recommended to do the setup in applicationDidFinishLaunchingWithOptions method.

  • Add an observer to the FCUUIDsOfUserDevicesDidChangeNotification to be notified about uuids of user devices changes.
  • If necessary, migrate from a previously used UUID or UDID using one of the migrations methods listed in the API section (it's recommended to do migration before calling uuidForDevice or uuidsForUserDevices methods). Keep in mind that migration works only if the existing value is a valid uuid and uuidForDevice has not been created yet.
  • Call any class method to enforce iCloud sync.

API

Get different UUIDs (each one with its own persistency level)

//changes each time (no persistent)
+(NSString *)uuid;

//changes each time (no persistent), but allows to keep in memory more temporary uuids
+(NSString *)uuidForKey:(id<NSCopying>)key;

//changes each time the app gets launched (persistent to session)
+(NSString *)uuidForSession;

//changes each time the app gets installed (persistent to installation)
+(NSString *)uuidForInstallation;

//changes each time all the apps of the same vendor are uninstalled (this works exactly as identifierForVendor)
+(NSString *)uuidForVendor;

//changes only on system reset, this is the best replacement to the good old udid (persistent to device)
+(NSString *)uuidForDevice;
//or
#import "UIDevice+FCUUID.h"
[[UIDevice currentDevice] uuid];

Get the list of UUIDs of user devices

//returns the list of all uuidForDevice of the same user, in this way it's possible manage guest accounts across multiple devices easily
+(NSArray *)uuidsOfUserDevices;

Migrate from a previously stored UUID / UDID Before migrating an existing value it's recommended to debug it by simply passing commitMigration:NO and logging the returned value. When you will be ready for committing the migration, use commitMigration:YES. After the migration, any future call to uuidForDevice will return the migrated value.

//these methods search for an existing UUID / UDID stored in the KeyChain or in UserDefaults for the given key / service / access-group
+(NSString *)uuidForDeviceMigratingValue:(NSString *)value commitMigration:(BOOL)commitMigration;
+(NSString *)uuidForDeviceMigratingValueForKey:(NSString *)key commitMigration:(BOOL)commitMigration;
+(NSString *)uuidForDeviceMigratingValueForKey:(NSString *)key service:(NSString *)service commitMigration:(BOOL)commitMigration;
+(NSString *)uuidForDeviceMigratingValueForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup commitMigration:(BOOL)commitMigration;

Check if value is a valid UUID

+(BOOL)uuidValueIsValid:(NSString *)uuidValue;

Persistence

  • yes
  • - no
  • * read notes below
PERSISTS App memory App relaunch Reset Advertising Identifier App reinstall System reboot System upgrade System reset
uuid - - - - - - -
uuidForKey:key - - - - - -
uuidForSession - - - - - -
uuidForInstallation - - -
uuidForVendor - * - -
uuidForDevice **

*(persists only if the user have not uninstalled all apps of the same vendor)

**(persists only if the user restores a device backup which includes also keychain's data)

FAQ

How can I share the device uuid between two apps?

You must have KeyChain sharing enabled (entitlements and provisioning profile) and your apps identifiers must have the same bundle seed.

What happens if I call uuidForDevice on 2 different devices using same iCloud account and iCloud Keychain?

You will obtain 2 different uuid(s), and if you call uuidsOfUserDevices you will obtain a list containing the uuids of both devices.

When I reboot / upgrade / reset my device system, will device uuid change?

Please check the persistence table above.

Support development

Donate

License

Released under MIT License.

fcuuid's People

Contributors

air7y avatar alexruperez avatar andschdk avatar dentelezhkin avatar fabiocaccamo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fcuuid's Issues

duplicated uuidForDevice when restoring from iCloud

Hey @fabiocaccamo, I'm having an issue when restoring a device using iCloud.

So, we are using uuidForDevice to have a unique id per user per device, but we are facing some issues when people are cloning their devices and as the uuidForDevice is the same (they do a full backup with encrypted data and everything), then for our system, the "new" app is the same user/same device.

Is there any chance to prevent this behavior? we might have users paying just for one device when they could be using several ones.

Thanks in advance!

Carthage support ?

Hi Team,

First, thanks for the work!

Would you consider an update if I do a PR with Carthage support?

Cheers,
Vincent

uuidForDevice

When i want to get uuid after the system is reinstalled, i must log in to iCloud ?

What if user doesn't use iCloud?

Hi, I find your library is perfect to accomplish my client's app requirements and identify users. I'd need to use the uuidForDevice method to identify the user device. However I have a few questions:

-As I understand your library, it relies in NSUbiquitousKeyValueStore to persist across installations but, what happens if the user is logged out or even never created a iCloud account? This app is meant to be used mostly by old people so this can be an usual scenario. If this is the case, there's nothing to do, Am I right? Or there is any kind of automatically generated iCloud id created on iPhone activation?

-Can you identify just the current device instead of every user devices?

Thank you very much

Ricardo Mantero

uuidForInstallation persists after reinstall

Not sure if I'm getting it right but based on the persistence table, the uuidForInstallation is expected to be removed when the app is uninstalled. However, that's not the case (tested on iOS 9 and 10). Probably because of the following line:

_uuidForInstallation = [self _getOrCreateValueForKey:_uuidForInstallationKey defaultValue:nil userDefaults:YES keychain:YES service:nil accessGroup:nil synchronizable:NO];

I believe keychain argument should be NO here.

_uuidForDevice starts to return the same UUID for different devices (issue probably started around iOS 16.6.1)

Hi,

we're currently seeing the case where 2 different iPads, which use the same apple ID would generate the same UUID, which is obviously not what one wants.

We don't know for sure, but it seems it all started with around iOS ~16.6.1.

Is anybody else seeing this, or even knows a fix for it?

Thanks a lot!

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

iCloud Keychain Syn

What Happens if iCloud is Sync Keychain and try to get device ID on 2 devices with same iCloud account.

Use with Swift project?

I have Swift project and added FCUUID throw pods. And now I don't now how to use it. Import can not find FCUUID framework. Please can you write/describe fully FAQ integrating into Swift project

Fund with Polar

same ID,one iphone ,two UDID

I use FCUUID as NSString *deviceUUID = [FCUUID uuidForDevice];,but` same ID,one iphone ,two UDID,log is NSUbiquitousKeyValueStore error: com.xxx.xxx has no valid com.apple.developer.ubiquity-kvstore-identifier entitlement,can you help me?

同一个设备登录多个appid,同步了keychain信息的话

同一个设备登录多个appid,同步了keychain信息的话,会导致获取的uuid发生变化吗?会被新的appid中的keychain信息覆盖掉?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Crash on uuid for device

"uuidForDeviceInMemory" is nil and calling "isEqualToString" on it causing crash.

line number in code

screen shot 2016-03-02 at 9 54 21 am

EDIT:

So here the scenario to generate
Use the UUIDForDevice, and then delete the app and reinstall it again,

IOS7 support

Before using i want to ensure does this plugin support ios7 and ios8. what it will return as UUID ? is it macid?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.