Skip to content

Instantly share code, notes, and snippets.

View alvaroroyo's full-sized avatar
🤠
Working from home

Alvaro Royo alvaroroyo

🤠
Working from home
View GitHub Profile
func getSomethingFromBackground(completion: @escaping (String)->()) {
DispatchQueue.global().async {
completion("Hello world!")
}
}
class UIXibView: UIView {
public var nibName:String? { return String(describing: type(of: self)) }
public var contentView: UIView!
override public init(frame: CGRect) {
super.init(frame: frame)
awakeFromNib()
}
override open func awakeFromNib() {
super.awakeFromNib()
let nibName = String(describing: type(of: self))
guard let view = Bundle.main.loadNibNamed(nibName, owner: self, options: nil)?.first as? UIView else { return }
view.frame = self.bounds
view.autoresizingMask = [.flexibleHeight,.flexibleWidth]
self.addSubview(view)
}
enum AppEnvironments {
case Dev, Pre, Pro
}
var environment: AppEnvironments {
get {
let bundleId = Bundle.main.bundleIdentifier ?? ""
switch bundleId {
case "com.timbrit.dev": return .Dev
case "com.timbrit.pre": return .Pre
#Set here your Environment.plist name
ENVIRONMENT="DEV"
#Environment.plist path
ENVIRONMENT_PLIST="$PROJECT_DIR/AppName/Environments.plist"
#Get app name from Environment.plist
APP_NAME=$(/usr/libexec/PlistBuddy -c "Print :$ENVIRONMENT:APP_NAME" "$ENVIRONMENT_PLIST")
#Get bundle identifier from Environment.plist
BUNDLE_ID=$(/usr/libexec/PlistBuddy -c "Print :$ENVIRONMENT:BUNDLE_IDENTIFIER" "$ENVIRONMENT_PLIST")
{
"auto_renew_status_change_date":"2019-09-20 11:13:26 Etc/GMT",
"environment":"Sandbox",
"auto_renew_status":"false",
"auto_renew_status_change_date_pst":"2019-09-20 04:13:26 America/Los_Angeles",
"latest_expired_receipt":"ewoJInNpZ25hdHVyZSIgPSAiQTVZc0kwRUFlZER0TWRpalVXYk5rcTJG...",
"latest_expired_receipt_info":{
"original_purchase_date_pst":"2019-09-20 03:44:04 America/Los_Angeles",
"quantity":"1",
"subscription_group_identifier":"205957",
{
"status": 0,
"environment": "Sandbox",
"receipt": {
"receipt_type": "ProductionSandbox",
"adam_id": 0,
"app_item_id": 0,
"bundle_id": "com.company.appName",
"application_version": "3583",
"download_id": 0,
{
"password" : "79b4e6583c2...ca7d504ed97",
"receipt-data" : "MIIeZwYJKoZIhvcNAQcCoIIeWDCCHlQCAQExCzAJBgUrDgMCGgUAMIIOCAYJKoZ..."
}
var receiptData: String? {
guard
let url = Bundle.main.appStoreReceiptURL,
let data = try? Data(contentsOf: url)
else { return nil }
return data.base64EncodedString()
}
func purchase(_ product: SKProduct) {
guard SKPaymentQueue.canMakePayments() else {
return
}
let payment = SKPayment(product: product)
let queue = SKPaymentQueue.default()
queue.add(payment)
queue.add(self) //Delegate
}