尝试在子视图中添加点击手势识别器以在购买后删除广告时出现以下错误。我用谷歌搜索,无法找出我做错了什么。
import UIKit
import StoreKit
import OAStackView
import SnapKit
import GoogleMobileAds
class SquaresViewController: UIViewController, SKProductsRequestDelegate, SKPaymentTransactionObserver {
let defaults = UserDefaults.standard
let stackView = OAStackView(frame: CGRect.zero)
let titleView = TitleView(frame: CGRect.zero)
let bannerView = BannerView(frame: CGRect.zero)
let removeAdsView = RemoveAdsView(frame: CGRect.zero)
var squaresCollectionView: UICollectionView!
var productID: NSString?
override func viewDidLoad() {
productID = "5daysubscription"
super.viewDidLoad()
SKPaymentQueue.default().add(self)
view.addSubview(stackView)
addStackView()
addTitleView()
addCollectionView()
addBannerView()
addRemoveAdsView()
removeAdsView.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self.removeAdsView, action: #selector(self.handleTap))
tap.numberOfTapsRequired = 1
removeAdsView.addGestureRecognizer(tap)
if (defaults.bool(forKey: "purchased")){
bannerView.isHidden = true
removeAdsView.isHidden = true
}
else if (!defaults.bool(forKey: "stonerPurchased")){
print("false")
}
}
func addRemoveAdsView() {
stackView.addArrangedSubview(removeAdsView)
removeAdsView.snp.makeConstraints { make in
make.height.equalTo(view.snp.height).multipliedBy(0.1)
make.bottom.equalTo(view.snp.bottom)
make.width.equalTo(stackView.snp.width)
}
}
func handleTap() {
if (SKPaymentQueue.canMakePayments())
{
let productID:NSSet = NSSet(object: self.productID!);
let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>);
productsRequest.delegate = self;
productsRequest.start();
print("Fetching Products");
}else{
print("Can't make purchases");
}
}
}
继承我的视图控制器:
import UIKit
import SnapKit
class RemoveAdsView: UIView {
var removeAdsText: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
self.translatesAutoresizingMaskIntoConstraints = false
self.backgroundColor = UIColor.gray
addCustomView()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func addCustomView() {
removeAdsText = UILabel(frame: CGRect.zero)
removeAdsText.text = "Tap here to remove ads."
removeAdsText.textAlignment = .center
removeAdsText.numberOfLines = 0
self.addSubview(removeAdsText)
removeAdsText.translatesAutoresizingMaskIntoConstraints = false
removeAdsText.snp.makeConstraints { make in
make.edges.equalTo( self.snp.edges )
}
}
}
子视图:
$( document ).ready(function() {
$("li:contains('\\135')").html(function () {
return $(this).html().replace("\\135", "<i class='fa fa-rocket'></i>");
});
$("li:contains('\\137')").html(function () {
return $(this).html().replace("\\137", "<i class='fa fa-chevron-circle-left'></i>");
});
});
我删除了一些可读性函数(StoreKit和视图中提到的其他函数加载)。谢谢你的帮助。