订阅购买
This commit is contained in:
parent
6565a309b1
commit
f5c7278a92
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<array/>
|
||||
</plist>
|
||||
Binary file not shown.
@ -649,53 +649,5 @@
|
||||
</Locations>
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "4BEF85E8-981C-436B-992D-07D59423A721"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "SwiftProject/Project/View/CustomSheetController/CustomSheetController.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "142"
|
||||
endingLineNumber = "142"
|
||||
landmarkName = "tableView(_:didSelectRowAt:)"
|
||||
landmarkType = "7">
|
||||
<Locations>
|
||||
<Location
|
||||
uuid = "4BEF85E8-981C-436B-992D-07D59423A721 - 771d9e5cdd706c61"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
symbolName = "SwiftProject.CustomSheetController.tableView(_: __C.UITableView, didSelectRowAt: Foundation.IndexPath) -> ()"
|
||||
moduleName = "SwiftProject"
|
||||
usesParentBreakpointCondition = "Yes"
|
||||
urlString = "file:///Users/aaa/Documents/IOS%20Dev/VR/SwiftProject/SwiftProject/Project/View/CustomSheetController/CustomSheetController.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "139"
|
||||
endingLineNumber = "139"
|
||||
offsetFromSymbolStart = "700">
|
||||
</Location>
|
||||
<Location
|
||||
uuid = "4BEF85E8-981C-436B-992D-07D59423A721 - 771d9e5cdd706c61"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
symbolName = "SwiftProject.CustomSheetController.tableView(_: __C.UITableView, didSelectRowAt: Foundation.IndexPath) -> ()"
|
||||
moduleName = "SwiftProject"
|
||||
usesParentBreakpointCondition = "Yes"
|
||||
urlString = "file:///Users/aaa/Documents/IOS%20Dev/VR/SwiftProject/SwiftProject/Project/View/CustomSheetController/CustomSheetController.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "139"
|
||||
endingLineNumber = "139"
|
||||
offsetFromSymbolStart = "168">
|
||||
</Location>
|
||||
</Locations>
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
||||
@ -40,7 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
Analytics.logEvent("user_launch", parameters: ["type":"new"])
|
||||
SKUPay.sharedInstance.requestProducts(productsIdentifiers: MemberShipModelItem.getProductsIDs())
|
||||
|
||||
SKUPay.sharedInstance.setUpUserInfo()
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "Diamond.png",
|
||||
"filename" : "Group_427320241.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "Diamond@2x.png",
|
||||
"filename" : "Group_427320241@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "Diamond@3x.png",
|
||||
"filename" : "Group_427320241@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1000 B |
Binary file not shown.
|
Before Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.7 KiB |
BIN
SwiftProject/SwiftProject/Assets.xcassets/vip_Diamond.imageset/Group_427320241.png
vendored
Normal file
BIN
SwiftProject/SwiftProject/Assets.xcassets/vip_Diamond.imageset/Group_427320241.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
SwiftProject/SwiftProject/Assets.xcassets/vip_Diamond.imageset/Group_427320241@2x.png
vendored
Normal file
BIN
SwiftProject/SwiftProject/Assets.xcassets/vip_Diamond.imageset/Group_427320241@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
BIN
SwiftProject/SwiftProject/Assets.xcassets/vip_Diamond.imageset/Group_427320241@3x.png
vendored
Normal file
BIN
SwiftProject/SwiftProject/Assets.xcassets/vip_Diamond.imageset/Group_427320241@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.6 KiB |
@ -24,38 +24,43 @@ class SKUPay:NSObject, SKRequestDelegate,SKProductsRequestDelegate,SKPaymentTran
|
||||
var productRequest:SKProductsRequest?
|
||||
var productsArr:[SKProduct] = []//存放请求到的商品条目,有效的商品
|
||||
var invalidProductIdentifiers:[String] = [] //存放已经无效(过期、被删除等)的商品
|
||||
var historyPaymentTransactions:[SKPaymentTransaction]? {
|
||||
get {
|
||||
let data = UserDefaults.standard.value(forKey: "kHistoryTransaction")
|
||||
var hpt:[SKPaymentTransaction]? = nil
|
||||
guard let dt = data else {
|
||||
return nil
|
||||
}
|
||||
do {
|
||||
hpt = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [SKPaymentTransaction.self], from: dt as! Data) as? [SKPaymentTransaction]
|
||||
|
||||
}
|
||||
catch {
|
||||
print("本地历史交易信息解析失败....")
|
||||
}
|
||||
return hpt
|
||||
|
||||
|
||||
func setTransactionDic(transactions:[SKPaymentTransaction]?) {
|
||||
guard let transactions else {
|
||||
UserDefaults.standard.setValue(nil, forKey: "kHistoryTransaction")
|
||||
UserDefaults.standard.synchronize()
|
||||
return
|
||||
}
|
||||
|
||||
set{
|
||||
guard let nv = newValue else {
|
||||
UserDefaults.standard.setValue(nil, forKey: "kHistoryTransaction")
|
||||
UserDefaults.standard.synchronize()
|
||||
return
|
||||
var arr:[Any] = []
|
||||
transactions.forEach { nv in
|
||||
var dic:[String:Any] = [:]
|
||||
dic["productIdentifier"] = nv.payment.productIdentifier
|
||||
dic["transactionState"] = nv.transactionState.rawValue
|
||||
arr.append(dic)
|
||||
}
|
||||
|
||||
UserDefaults.standard.setValue(arr, forKey: "kHistoryTransaction")
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
|
||||
//此处初始化用户信息
|
||||
func setUpUserInfo() {
|
||||
let arr:[Any]? = UserDefaults.standard.value(forKey: "kHistoryTransaction") as? [Any] ?? nil
|
||||
guard let arr else {
|
||||
return
|
||||
}
|
||||
|
||||
arr.forEach { item in
|
||||
let it = item as! [String:Any]
|
||||
let productIdentifier = it["productIdentifier"] as? String
|
||||
let stateRawValue = it["transactionState"] as? Int
|
||||
let state = SKPaymentTransactionState(rawValue:stateRawValue ?? 2)
|
||||
if (state == .purchased || state == .restored) {//检查到用户有购买
|
||||
UserInfo.sharedInstance.paymentState = true
|
||||
UserInfo.sharedInstance.paymentProductIdentifier = productIdentifier
|
||||
}
|
||||
do {
|
||||
let data = try NSKeyedArchiver.archivedData(withRootObject: nv, requiringSecureCoding: false)
|
||||
UserDefaults.standard.setValue(data, forKey: "kHistoryTransaction")
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
catch {
|
||||
print("本地存储交易信息失败....")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,9 +84,16 @@ class SKUPay:NSObject, SKRequestDelegate,SKProductsRequestDelegate,SKPaymentTran
|
||||
}
|
||||
|
||||
//MARK: - 支付
|
||||
func pay(product:SKProduct) {
|
||||
let payment = SKPayment(product: product)
|
||||
SKPaymentQueue.default().add(payment)
|
||||
func pay(productIdentifier:String) {
|
||||
if !self.productsArr.isEmpty {
|
||||
let product = self.productsArr.filter {
|
||||
$0.productIdentifier == productIdentifier
|
||||
}.first
|
||||
if let pd = product {
|
||||
let payment = SKPayment(product: pd)
|
||||
SKPaymentQueue.default().add(payment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - 恢复购买
|
||||
@ -119,7 +131,8 @@ class SKUPay:NSObject, SKRequestDelegate,SKProductsRequestDelegate,SKPaymentTran
|
||||
// Sent when the transaction array has changed (additions or state changes). Client should check state of transactions and finish as appropriate.
|
||||
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]){
|
||||
if !transactions.isEmpty {
|
||||
self.historyPaymentTransactions = transactions
|
||||
// self.historyPaymentTransactions = transactions
|
||||
self.setTransactionDic(transactions: transactions)
|
||||
|
||||
transactions.forEach { spt in
|
||||
|
||||
|
||||
@ -8,10 +8,11 @@
|
||||
import Foundation
|
||||
class UserInfo: NSObject {
|
||||
static let sharedInstance = UserInfo()
|
||||
|
||||
var paymentState:Bool = false
|
||||
var paymentProductIdentifier:String? //表示已购买的产品id
|
||||
var isMemberShip:Bool {
|
||||
get {
|
||||
return false
|
||||
return paymentState
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ class MemberShipModelItem: NSObject {
|
||||
|
||||
//目前就3个
|
||||
class func getProductsIDs()->[String] {
|
||||
return ["VPC00001","VPC00002","VPC00003"]
|
||||
return ["VPC0000001","VPC0000002","VPC0000003"]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,9 +16,9 @@ extension MembershipVC {
|
||||
self.setLeftOneBtnImg(imgStr: "membership_close")
|
||||
self.leftBtn1?.addTarget(self, action: #selector(dismissVC(sender: )), for: .touchUpInside)
|
||||
// self.setRightOneBtnImg(imgStr: "Icon_PopUp_Icon_Folder")
|
||||
self.rightBtn1?.addTarget(self, action: #selector(buyMembership(sender: )), for: .touchUpInside)
|
||||
self.rightBtn1?.addTarget(self, action: #selector(rebuyMembership(sender: )), for: .touchUpInside)
|
||||
self.setRightOneBtnTitle(string: NSLocalizedString("restorevip", comment: "") as NSString)
|
||||
self.rightBtn1?.isHidden = false
|
||||
self.rightBtn1?.isHidden = UserInfo.sharedInstance.isMemberShip
|
||||
self.view.addSubview(mTopImgView)
|
||||
|
||||
let topView = self.topView()
|
||||
@ -64,8 +64,14 @@ extension MembershipVC {
|
||||
|
||||
//MARK: - 购买会员
|
||||
@objc func buyMembership(sender:UIButton) {
|
||||
SKUPay.sharedInstance.pay(productIdentifier: (self.selectedItem?.productIdentifier!)!)
|
||||
}
|
||||
|
||||
//恢复购买
|
||||
@objc func rebuyMembership(sender:UIButton) {
|
||||
|
||||
}
|
||||
|
||||
func topView() -> UIView {
|
||||
let bgView = UIView()
|
||||
let imgView = UIImageView()
|
||||
@ -174,7 +180,7 @@ extension MembershipVC {
|
||||
let item1 = MemberShipModelItem(title: "$0.99/周", desc: "一周", rightDesc: "", isSelected: false, imageName_selected: NSLocalizedString("vip_product_week", comment: ""), imageName_unSelected: NSLocalizedString("vip_product_unselect_week", comment: ""), productIdentifier: MemberShipModelItem.getProductsIDs()[0])
|
||||
arr.append(item1)
|
||||
|
||||
let item2 = MemberShipModelItem(title: "$1.99/周", desc: "一月", rightDesc: "90%的人选择", isSelected: false, imageName_selected: NSLocalizedString("vip_product_month", comment: ""), imageName_unSelected: NSLocalizedString("vip_product_unselect_month", comment: ""), productIdentifier: MemberShipModelItem.getProductsIDs()[1])
|
||||
let item2 = MemberShipModelItem(title: "$1.99/月", desc: "一月", rightDesc: "90%的人选择", isSelected: true, imageName_selected: NSLocalizedString("vip_product_month", comment: ""), imageName_unSelected: NSLocalizedString("vip_product_unselect_month", comment: ""), productIdentifier: MemberShipModelItem.getProductsIDs()[1])
|
||||
arr.append(item2)
|
||||
|
||||
let item3 = MemberShipModelItem(title: "$9.99/年", desc: "一年", rightDesc: "50%的人选择", isSelected: false, imageName_selected: NSLocalizedString("vip_product_year", comment: ""), imageName_unSelected: NSLocalizedString("vip_product_unselect_year", comment: ""), productIdentifier: MemberShipModelItem.getProductsIDs()[1])
|
||||
@ -208,9 +214,11 @@ extension MembershipVC {
|
||||
// subscribeBtn.setTitle(UserInfo.sharedInstance.isMemberShip ?NSLocalizedString("Membership activated", comment: "") : NSLocalizedString("Free Trail 3 Days", comment: ""), for: .normal)
|
||||
if UserInfo.sharedInstance.isMemberShip {
|
||||
subscribeBtn.setBackgroundImage(UIImage(named: NSLocalizedString("vip_alreadybuybtn", comment: "")), for: .normal)
|
||||
subscribeBtn.isEnabled = false
|
||||
}
|
||||
else {
|
||||
subscribeBtn.setBackgroundImage(UIImage(named: NSLocalizedString("vip_buybtn", comment: "")), for: .normal)
|
||||
subscribeBtn.isEnabled = true
|
||||
}
|
||||
|
||||
subscribeBtn.backgroundColor = UserInfo.sharedInstance.isMemberShip ? .lightGray : .darkText
|
||||
@ -225,6 +233,8 @@ extension MembershipVC {
|
||||
make.right.equalToSuperview().offset(-4)
|
||||
}
|
||||
|
||||
subscribeBtn.addTarget(self, action: #selector(buyMembership(sender: )), for: .touchUpInside)
|
||||
|
||||
|
||||
let btn_privateBtn = UIButton()
|
||||
bgView.addSubview(btn_privateBtn)
|
||||
@ -267,9 +277,6 @@ extension MembershipVC {
|
||||
let descLabel = UILabel()
|
||||
bgView.addSubview(descLabel)
|
||||
descLabel.numberOfLines = 0
|
||||
// descLabel.font = UIFont.systemFont(ofSize: 10)
|
||||
// descLabel.textColor = UIColor(r: 205, g: 205, b: 205, a: 1)
|
||||
// descLabel.text = NSLocalizedString("subscribDesc", comment: "")
|
||||
descLabel.textAlignment = .center
|
||||
descLabel.snp.makeConstraints { make in
|
||||
make.left.equalToSuperview().offset(4)
|
||||
@ -277,11 +284,7 @@ extension MembershipVC {
|
||||
make.top.equalTo(btn_userBtn.snp.bottom).offset(12)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
descLabel.textColor = UIColor(red: 0.804, green: 0.804, blue: 0.804, alpha: 1)
|
||||
descLabel.font = UIFont(name: "PingFangSC-Regular", size: 10)
|
||||
descLabel.lineBreakMode = .byWordWrapping
|
||||
@ -290,10 +293,6 @@ extension MembershipVC {
|
||||
paragraphStyle.alignment = .center
|
||||
descLabel.attributedText = NSMutableAttributedString(string: NSLocalizedString("subscribDesc", comment: ""), attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return bgView
|
||||
}
|
||||
|
||||
|
||||
@ -590,6 +590,9 @@ class VRVideoTransformController: BaseController {
|
||||
self!.videoHeight = 720
|
||||
self!.according3DFormatShowList(format: self!.selected3DFormat)
|
||||
}
|
||||
else if(text == NSLocalizedString("取消", comment: "")){
|
||||
//....什么都不需要做,但要有该行
|
||||
}
|
||||
else {
|
||||
if !UserInfo.sharedInstance.isMemberShip {
|
||||
//不是就跳转引导购买
|
||||
@ -641,6 +644,9 @@ class VRVideoTransformController: BaseController {
|
||||
self!.selectedBitsPerPixel = .low
|
||||
self!.according3DFormatShowList(format: self!.selected3DFormat)
|
||||
}
|
||||
else if(text == NSLocalizedString("取消", comment: "")){
|
||||
//....什么都不需要做,但要有该行
|
||||
}
|
||||
else {
|
||||
if !UserInfo.sharedInstance.isMemberShip {//判断是否为vip
|
||||
//不是就跳转引导购买
|
||||
|
||||
@ -101,7 +101,7 @@
|
||||
"membershipdesc_4" = "No Ads";
|
||||
"Free Trail 3 Days" = "Free Trail 3 Days";
|
||||
"subscribDesc" = "Free trial for 3 days. After the trial ends, renew according to the fee shown in the picture. You can unsubscribe at any time in the Apple Store. If subscribed or successfully paid but not displayed, the same ApplelD can be used to restore membership. After confirming the purchase, the payment will be deducted from your account. Automatic renewal will be deducted before the expiration date. You can go to the ApplelD management page to close the subscription.";
|
||||
"用户协议" = "用户协议";
|
||||
"用户协议" = "Terms of Service";
|
||||
"Membership activated" = "Membership activated";
|
||||
"restorevip" = "Restore";
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user