ios - 检测首次在 iOS 中安装 NOT NSUserDefaults

标签 ios cocoa-touch nsuserdefaults

工作原理 - 该应用是跨平台服务的订阅。在 iphone 上,首次购买将为您提供 30 天的完整功能,然后 30 天后您将无法执行某些操作,直到您通过应用内购买购买订阅。

我需要什么 - 我需要知道这是否是第一次运行,以便我可以将用户信息添加到数据库中。或者因为它是跨平台的,他们可能已经支付了订阅费用,所以我需要为用户现有的订阅增加 30 天。

我现在在做什么 - 目前我将 identifierForVendor 存储在远程数据库中,在 NSUserDefaults 中有一个 bool 值检查以查看 1. 如果它是第一次运行和 2. 如果它是第一次运行允许用户将自己添加到数据库中以进行 30 天的完整使用,或将 30 天添加到他们现有的订阅中。

问题 - 问题是,如果用户删除应用程序然后重新安装它,NSUserDefaults 也将被删除,identifierForVendor 将更改,这将允许用户再添加 30 天只需删除并重新安装应用程序即可免费订阅。

理想方案 本来想做app的订阅,但是不知道当初购买app时如何查看收据,将用户插入到远程数据库中。此外,我真的不知道如何设置非应用内购买的订阅。我还考虑过让应用程序免费,然后他们可以使用应用程序内购买来购买服务,但是如果无法连接到远程服务器以首先建立数据,应用程序就毫无用处。

底线我想执行以下操作之一

  1. 在第一次购买时进行订阅(我需要能够检测购买是否有效,以便将用户信息输入远程数据库)
  2. 让应用免费,然后使用应用内购买来添加订阅(是否可以接受免费应用在您订阅之前什么也做不了?)
  3. 保留它现在的样子(但是为 identifierForVendor 找到一个更永久的解决方案,identifierForAdvertising 也不会工作,因为它可以被关闭)

最佳答案

这对你很有帮助。基本上它是在 NSUserDefaults 之后设计的钥匙串(keychain)包装器。它帮助了我很多。将东西存储在 Keychain 中可以让它们在应用程序重新安装后保持不变。

https://github.com/carlbrown/PDKeychainBindingsController

This project is intended to make using the Mac OSX and iOS Keychains as easy as NSUserDefaults.

It is a KVO-compliant Cocoa wrapper around the Mac OSX and iOS Keychains, and the model for this wrapper is NSUserDefaults, so the intent is that for the common cases you would normally want to call:

[NSUserDefaultsController sharedUserDefaultsController] You should be able to call

[PDKeychainBindingsController sharedKeychainBindingsController] And for the common cases you normally would have called:

[NSUserDefaults standardUserDefaults] You should be able to call

[PDKeychainBindings sharedKeychainBindings]

关于ios - 检测首次在 iOS 中安装 NOT NSUserDefaults,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13996582/

相关文章:

objective-c - 在带有协议(protocol)和委托(delegate)的 viewDidLoad 之后,字符串变为 nil

iphone - 如何拉伸(stretch)单元格背景图像而不像 iPhone 中的聊天气泡那样的特定部分?

objective-c - iOS:addObserver 和 superview 查询

objective-c - 从 subview 中推送 Controller

iOS - UserDefaults 源文件替换

iphone - NSUserDefaults 是否会通过更新 Appstore 中的应用程序而持续存在?

ios - 获取 UICollectionView 的按下和常量坐标

objective-c - 如何从 cocoa 中的另一个文件设置对象的属性?

ios - otest 崩溃与 -[id<NSURLAuthenticationChallengeSender> userCredential :]

iphone - 使用 NSUserDefaults 保存和加载数据需要帮助