我刚刚提交了我的第一个包含应用内购买的应用,它已于昨晚获得批准。我下载了我的应用并尝试购买应用内购买以进行测试,但令我惊讶的是,当提供应用内选项的按钮被点击时,它会崩溃。更有趣的是,它只是在从Appstore下载时崩溃,我删除了应用程序并直接从我的计算机/ XCode重新下载它并且应用程序没有崩溃。
在审核应用时,是否有可能将网址更改为使用sendbox进行测试?
这是我用于制作的网址:
let storeURL = NSURL(string: "https://buy.itunes.apple.com/verifyReceipt")
这是我用于测试的网址,在提交给Appstore时被注释掉了:
let storeURL = NSURL(string: "https:/sandbox.itunes.apple.com/verifyReceipt")
此外,当应用审核并离开测试网址时,是否有可能更改网址以进行测试?
有没有办法知道Appstore中正在使用的URL?
由于
于2016年10月18日编辑:
以下是我正在使用的代码......有人可以如此善良并快速查看是否有问题,尤其是accessPremiumFeature
方法,这是一个被调用的方法。崩溃正在发生?
仅供参考 - 我仍然没有错误详细信息,因为我无法在本地重现该应用程序,并且该应用程序已在几小时前获得批准。
AppDelegate.swif
import StoreKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var canPurchase:Bool = false
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if SKPaymentQueue.canMakePayments(){
self.canPurchase = true
IAPManager.sharedInstance.setupInAppPurchases()
}
return true
}
}
SettingsViewController.swift - 这是调用accessPremiumFeature
时发生崩溃的地方。这里有什么不对吗?
import StoreKit
class SettingsViewController: UIViewController {
@IBAction func accessPremiumFeature() {
if NSUserDefaults.standardUserDefaults().boolForKey("com.domain.appName"){
let alert = UIAlertController(title: "PRO-Version", message: "You already have the PRO version.", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}else{
var productInfo:SKProduct?
for product in IAPManager.sharedInstance.products{
productInfo = product as? SKProduct
}
let alertController = UIAlertController(title: "Premium Features", message: "Unlock all premium features for \(productInfo!.price)." + "This includes... bla, bla, bla...", preferredStyle: .Alert)
alertController.view.tintColor = UIColor.myRedColor()
let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil)
let buyAction = UIAlertAction(title: "Buy", style: .Default) { (action) -> Void in
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("StoreTableView") as! StoreTableViewController
self.presentViewController(vc, animated: true, completion: nil)
}
alertController.addAction(okAction)
alertController.addAction(buyAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
}
IAPManager.swift - 这是主要的应用内购买代码(Brain)。
import StoreKit
// protocol to notify when user restores purchase
protocol IAPManagerDelegate {
func managerDidRestorePurchases()
}
class IAPManager: NSObject, SKProductsRequestDelegate, SKPaymentTransactionObserver, SKRequestDelegate {
static let sharedInstance = IAPManager()
var request:SKProductsRequest!
var products:NSArray!
var delegate:IAPManagerDelegate?
//Load product identifiers for store usage
func setupInAppPurchases(){
self.validateProductIdentifiers(self.getProductIdentifiersFromMainBundle())
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}
//Get product identifiers
func getProductIdentifiersFromMainBundle() -> NSArray {
var identifiers = NSArray()
if let url = NSBundle.mainBundle().URLForResource("iap_product_ids", withExtension: "plist"){
identifiers = NSArray(contentsOfURL: url)!
}
return identifiers
}
//Retrieve product information
func validateProductIdentifiers(identifiers:NSArray) {
let productIdentifiers = NSSet(array: identifiers as [AnyObject])
let productRequest = SKProductsRequest(productIdentifiers: productIdentifiers as! Set<String>)
self.request = productRequest
productRequest.delegate = self
productRequest.start()
}
func createPaymentRequestForProduct(product:SKProduct){
let payment = SKMutablePayment(product: product)
payment.quantity = 1
SKPaymentQueue.defaultQueue().addPayment(payment)
}
func verifyReceipt(transaction:SKPaymentTransaction?){
let receiptURL = NSBundle.mainBundle().appStoreReceiptURL!
if let receipt = NSData(contentsOfURL: receiptURL){
//Receipt exists
let requestContents = ["receipt-data" : receipt.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))]
//Perform request
do {
let requestData = try NSJSONSerialization.dataWithJSONObject(requestContents, options: NSJSONWritingOptions(rawValue: 0))
//Build URL Request
let storeURL = NSURL(string: "https://buy.itunes.apple.com/verifyReceipt")// production URL
//let storeURL = NSURL(string: "https:/sandbox.itunes.apple.com/verifyReceipt") // Testing URL
let request = NSMutableURLRequest(URL: storeURL!)
request.HTTPMethod = "Post"
request.HTTPBody = requestData
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request, completionHandler: { (responseData:NSData?, response:NSURLResponse?, error:NSError?) -> Void in
do {
let json = try NSJSONSerialization.JSONObjectWithData(responseData!, options: .MutableLeaves) as! NSDictionary
print(json)
if (json.objectForKey("status") as! NSNumber) == 0 {
if let latest_receipt = json["latest_receipt_info"]{
self.validatePurchaseArray(latest_receipt as! NSArray)
} else {
let receipt_dict = json["receipt"] as! NSDictionary
if let purchases = receipt_dict["in_app"] as? NSArray{
self.validatePurchaseArray(purchases)
}
}
if transaction != nil {
SKPaymentQueue.defaultQueue().finishTransaction(transaction!)
}
dispatch_sync(dispatch_get_main_queue(), { () -> Void in
self.delegate?.managerDidRestorePurchases()
})
} else {
//Debug the receipt
print(json.objectForKey("status") as! NSNumber)
}
} catch {
print(error)
}
})
task.resume()
} catch {
print(error)
}
} else {
//Receipt does not exist
print("No Receipt")
}
}
func validatePurchaseArray(purchases:NSArray){
for purchase in purchases as! [NSDictionary]{
self.unlockPurchasedFunctionalityForProductIdentifier(purchase["product_id"] as! String)
}
}
func unlockPurchasedFunctionalityForProductIdentifier(productIdentifier:String){
NSUserDefaults.standardUserDefaults().setBool(true, forKey: productIdentifier)
NSUserDefaults.standardUserDefaults().synchronize()
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}
func lockPurchasedFunctionalityForProductIdentifier(productIdentifier:String){
NSUserDefaults.standardUserDefaults().setBool(false, forKey: productIdentifier)
NSUserDefaults.standardUserDefaults().synchronize()
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}
//MARK: SKProductsRequestDelegate
func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
self.products = response.products
print(self.products)
}
// MARK: SKPaymentTransactionObserver Protocol
func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions as [SKPaymentTransaction]{
switch transaction.transactionState{
case .Purchasing:
print("Purchasing")
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
case .Deferred:
print("Deferrred")
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
case .Failed:
print("Failed")
print(transaction.error?.localizedDescription)
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
case.Purchased:
print("Purchased")
self.verifyReceipt(transaction)
case .Restored:
print("Restored")
}
}
}
func restorePurchases(){
let request = SKReceiptRefreshRequest()
request.delegate = self
request.start()
}
func requestDidFinish(request: SKRequest) {
self.verifyReceipt(nil)
}
}
答案 0 :(得分:1)
您可以尝试使用Charles HTTP Proxy并查看请求的URL或使用hex-viewer打开App并搜索字符串。