Comments (5)
Thanks @lvcloudgit, that's one strange issue. Zip doesn't have anything to do with StoreKit.
Can you share some code so I can investigate your issue further?
from zip.
@marmelroy Thanks for your reply!
My code is a bit chaos and I don't know which part should be posted... But I found another possibility, still it's not work every time, but maybe it shows some tips?
The Build Settings of TARGETS has an Option "Always Embed Swift Standard Libraries", the value is "No" by default. I change it to "Yes", the error just disappeared!
But still... It's really bothered me, next morning, the error happened again! And I just change this option back to "No", the error disappeared!
So right now, seems the solution is just switch this option... would you take a guess where the problem could be?
This is the IAPHelper.swift code:
import Foundation
import StoreKit
public typealias bookId = String
public typealias BooksRequestCompleteHandler = (_ success: Bool, _ books:[SKProduct]?) -> ()
open class IAPHelper: NSObject {
static let IAPHelperPurchaseNotification = "IAPHelperPurchaseNotification"
var books: Set<bookId>
fileprivate var purchasedBookIds:Set<bookId> = Set()
var aRequest:SKProductsRequest?
var booksRequestFinishedHandler: BooksRequestCompleteHandler?
init(bookIds: Set<bookId>) {
books = bookIds
for id in bookIds {
let purchased = UserDefaults.standard.bool(forKey: id)
if purchased {
purchasedBookIds.insert(id)
} else {
}
}
super.init()
SKPaymentQueue.default().add(self)
}
}
// MARK: StoreKit API
extension IAPHelper {
public func requestProducts(_ completionHandler: @escaping BooksRequestCompleteHandler) {
aRequest?.cancel()
booksRequestFinishedHandler = completionHandler
aRequest = SKProductsRequest(productIdentifiers: books)
aRequest!.delegate = self
aRequest!.start()
}
public func buyProduct(_ product: SKProduct) {
let payment = SKPayment(product: product)
SKPaymentQueue.default().add(payment)
}
public func isProductPurchased(_ productIdentifier: bookId) -> Bool {
return purchasedBookIds.contains(productIdentifier)
}
public class func canMakePayments() -> Bool {
return SKPaymentQueue.canMakePayments()
}
public func restorePurchases() {
SKPaymentQueue.default().restoreCompletedTransactions()
}
}
// MARK: SKProductsRequestDelegate
extension IAPHelper: SKProductsRequestDelegate {
public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
let booksGet = response.products
booksRequestFinishedHandler?(true, booksGet)
clearRequestANdHandler()
public func request(_ request: SKRequest, didFailWithError error: Error) {
booksRequestFinishedHandler?(false, nil)
clearRequestANdHandler()
}
public func clearRequestANdHandler() {
aRequest = nil
booksRequestFinishedHandler = nil
}
}
// MARK: SKPaymentTransactionObserver
extension IAPHelper: SKPaymentTransactionObserver {
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch (transaction.transactionState) {
case .purchased:
completeTransaction(transaction)
break
case .failed:
failedTransaction(transaction)
break
case .restored:
restoreTransaction(transaction)
break
case .deferred:
break
case .purchasing:
break
}
}
}
fileprivate func completeTransaction(_ transaction: SKPaymentTransaction) {
UserDefaults.standard.set(true, forKey: transaction.payment.productIdentifier)
deliverPurchaseNotificatioForIdentifier(transaction.payment.productIdentifier)
SKPaymentQueue.default().finishTransaction(transaction)
}
fileprivate func restoreTransaction(_ transaction: SKPaymentTransaction) {
guard let productIdentifier = transaction.original?.payment.productIdentifier else { return }
deliverPurchaseNotificatioForIdentifier(productIdentifier)
SKPaymentQueue.default().finishTransaction(transaction)
}
fileprivate func failedTransaction(_ transaction: SKPaymentTransaction) {
if transaction.error!._code != SKError.paymentCancelled.rawValue {
print("Transaction Error: \(transaction.error?.localizedDescription)")
}
SKPaymentQueue.default().finishTransaction(transaction)
}
fileprivate func deliverPurchaseNotificatioForIdentifier(_ identifier: String?) {
guard let identifier = identifier else { return }
purchasedBookIds.insert(identifier)
UserDefaults.standard.set(true, forKey: identifier)
UserDefaults.standard.synchronize()
NotificationCenter.default.post(name: Notification.Name(rawValue: IAPHelper.IAPHelperPurchaseNotification), object: identifier)
}
}
/// get productIdentifiers
class PurchaseBooks {
var bookListArray:[String] {
didSet {
self.bookIds = Set(bookListArray)
self.store = IAPHelper(bookIds: self.bookIds)
}
}
var bookIds:Set<bookId> = []
var store:IAPHelper?
init() {
bookListArray = bookListData?.allKeys as! [String]
bookListArray = []
bookIds = Set(bookListArray)
store = IAPHelper(bookIds: self.bookIds)
}
}
var bookPurchase = PurchaseBooks()
** This is the
from zip.
The part of Unzip:
func resetDefaultBookOffline() {
let defaultZip = Bundle.main.path(forResource: "defaultResource", ofType: "zip")
let booklistFile = "\(documentPath)/BookList.plist"
let fileMgr = FileManager.default
if fileMgr.fileExists(atPath: booklistFile) == false {
do {
try _ = Zip.unzipFile(URL(string: defaultZip!)!, destination: URL(string:documentPath)!, overwrite: false, password: nil, progress: {
(progress: Double) -> () in
// print("Unzip progress: \(progress)\n")
})
try? fileMgr.removeItem(atPath: documentPath + "/__MACOSX")
try? fileMgr.removeItem(atPath: documentPath + "/default.zip")
print("Unzip complete, path:\(documentPath)")
} catch let error {
print("Unzip error:\(error.localizedDescription)")
}
}
}
from zip.
I'm sorry, it still can't work well. The error is:
It's not always happened, but sometimes. What's this mean? Why is that?
Sometimes it just happened in running Profile mode.
from zip.
I just use unzip once all over the project, as the code I just posted, pretty simple.
I think it's not caused by any specific code, maybe it caused by some build settings options?
from zip.
Related Issues (20)
- Invalid semantic version string '2.1'
- progressHandler called twice with 1.0 value
- UNZip file hang the UI and do nothing
- Any tutorial for manually import Zip framework?
- Compilation Error with Optional UnsafeMutableRawPointer in Xcode 13 RC HOT 5
- Missing folder inside zipped file
- 'ioapi.h' file not found in xcode 13.1
- Question
- Unzipping also returns unzipped url to a corrupted file in a __MACOSX directory
- Not able to use zip.xcframework HOT 7
- Special characters
- Error when use version 2.1.2 HOT 2
- Unable to zip file from URL HOT 1
- _
- missing symbol called - xcframework
- Can’t zip 4000 plus files HOT 1
- not work on Mac 13.4.1
- Security vulnerability in Zip package
- Please update deployment target to 11.0
- Path traversal vulnerability HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zip.