简体   繁体   中英

Uniquely identify iOS iTunes accounts using App Store receipts?

There are several questions on SO that discuss mechanisms for uniquely identifying iOS users by their iTunes account (for instance, Uniquely identifying an iOS user ). I've been trying to implement this in a different way, basically using the App Store receipt's opaque value field. This article seems to suggest that (at least for OS X apps) the opaque value field basically contains a unique ID to the user's iTunes account (NOT the email address, of course!), which suggests that this ID would be the same for different devices under the same iTunes account.

I've tried this on apps with no in-app purchase implemented, but I'm seeing that while the appStoreReceiptURL property of NSBundle contains a valid URL, that file never exists in the apps that I've tried (which were downloaded from the app store and were then updated with the test code using Xcode).

Is the receipt supposed to always exist, even for free/paid apps without IAP? Has anyone attempted to uniquely identify iTunes users using the receipt? It seems like a very promising approach.

You need to make an SKReceiptRefreshRequest to generate a receipt if you can't find one.

let receiptRequest = SKReceiptRefreshRequest()
receiptRequest.delegate = self
receiptRequest.start()

The below link has tips for a few other issues you may encounter:

App Store Receipt Validation

I was trying to solve the same problem. What I understood is there is no unique ID we can trust in Apple documentation but possible workaround is to use iCloud record ID.

Using iCloud record ID (CKRecordID)

Swift3/4+

    let container = CKContainer.default()
    container.fetchUserRecordID() {
        recordID, error in

        if let err = error {
            print(err.localizedDescription)
        }
        else if recID = recordID {
            print("fetched ID \(recID.recordName ?? "NA")")
        }
    }

For automatically created records, the ID name string is based on a UUID and is therefore guaranteed to be unique.

In Purchase receipt

In my case, I wanted to block upgrade/downgrade by DIFFERENT iTunes account in server side. So I use original_purchase_date for this (Assuming multiple purchase is impossible in one user account at the same fraction of time). This ID will be same always after initial purchase for that particular iTunes account. I save this ID in server along with Product_ID and always check this ID in receipt when user upgrade/downgrade (When app send new receipt). If it's different for same product ID, I assume it's different user tries to upgrade the product.

original_purchase_date - In an auto-renewable subscription receipt, this indicates the beginning of the subscription period, even if the subscription has been renewed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM