应用内购买无法连接到 iTunes Store
In-app purchase cannot connect to iTunes Store
在我的应用中,我想要一个应用内购买来删除横幅添加,我写了这段代码:
if adBannerView != nil{
let userDefaults = NSUserDefaults.standardUserDefaults()
if userDefaults.boolForKey("proUser") {
self.adBannerView?.hidden = true
}
} else {
self.adBannerView?.hidden = true
}
self.canDisplayBannerAds = true
self.adBannerView?.delegate = self
self.adBannerView?.hidden = true
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.adBannerView?.hidden = false
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
self.adBannerView?.hidden = true
}
而且,这是我的 "no-ads" 按钮代码
@IBAction func noAds(sender: AnyObject) {
PFPurchase.buyProduct("com.**.***", block: { (error:NSError?) -> Void in
if error != nil {
let alert = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
})
}
但是,当我在模拟器上 运行 我的应用程序时,它会给我一个警告 window,首先它说 "Do you want to purchase no ad for [=24=].99?",然后我按 "buy",它会等待一会儿,弹出一个警告window,说"Cannot connect to iTunes Store",我搜索了原因,一些网页说"You might wrote some code wrong",所以谁能帮我看看这些代码有问题吗?
此外,这是我在 AppDelegate 中的代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.enableLocalDatastore()
Parse.setApplicationId("****************************",
clientKey: "****************************")
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
PFPurchase.addObserverForProduct("com.**.***", block: { (trasition:SKPaymentTransaction!) -> Void in
let userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setBool(true, forKey: "proUser")
userDefaults.synchronize()
})
return true
}
我使用 Parse 启用应用内购买。
据我所知,无法在模拟器中测试应用内购买 (IAP)。要测试它们,您需要使用真实设备并使用专门设置为测试用户的 iTunes 帐户。
在我的应用中,我想要一个应用内购买来删除横幅添加,我写了这段代码:
if adBannerView != nil{
let userDefaults = NSUserDefaults.standardUserDefaults()
if userDefaults.boolForKey("proUser") {
self.adBannerView?.hidden = true
}
} else {
self.adBannerView?.hidden = true
}
self.canDisplayBannerAds = true
self.adBannerView?.delegate = self
self.adBannerView?.hidden = true
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.adBannerView?.hidden = false
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
self.adBannerView?.hidden = true
}
而且,这是我的 "no-ads" 按钮代码
@IBAction func noAds(sender: AnyObject) {
PFPurchase.buyProduct("com.**.***", block: { (error:NSError?) -> Void in
if error != nil {
let alert = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
})
}
但是,当我在模拟器上 运行 我的应用程序时,它会给我一个警告 window,首先它说 "Do you want to purchase no ad for [=24=].99?",然后我按 "buy",它会等待一会儿,弹出一个警告window,说"Cannot connect to iTunes Store",我搜索了原因,一些网页说"You might wrote some code wrong",所以谁能帮我看看这些代码有问题吗?
此外,这是我在 AppDelegate 中的代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.enableLocalDatastore()
Parse.setApplicationId("****************************",
clientKey: "****************************")
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
PFPurchase.addObserverForProduct("com.**.***", block: { (trasition:SKPaymentTransaction!) -> Void in
let userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setBool(true, forKey: "proUser")
userDefaults.synchronize()
})
return true
}
我使用 Parse 启用应用内购买。
据我所知,无法在模拟器中测试应用内购买 (IAP)。要测试它们,您需要使用真实设备并使用专门设置为测试用户的 iTunes 帐户。