-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from apphud/develop
feat: implemented delegate methods
- Loading branch information
Showing
12 changed files
with
338 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#import <React/RCTBridgeModule.h> | ||
#import <React/RCTEventEmitter.h> | ||
#import <React/RCTUtils.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#import <React/RCTBridgeModule.h> | ||
#import <React/RCTEventEmitter.h> | ||
|
||
@interface RCT_EXTERN_MODULE(ApphudSdkEvents, RCTEventEmitter) | ||
|
||
RCT_EXTERN_METHOD( | ||
setApphudProductIdentifiers:(NSArray)ids | ||
withResolve:(RCTPromiseResolveBlock)resolve | ||
withReject:(RCTPromiseRejectBlock)reject | ||
) | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import Foundation | ||
import React | ||
import ApphudSDK | ||
import StoreKit | ||
|
||
@objc(ApphudSdkEvents) | ||
class ApphudSdkEvents: RCTEventEmitter { | ||
|
||
var productIdentifiers:[String] = []; | ||
|
||
override init() { | ||
super.init(); | ||
Apphud.setDelegate(self); | ||
Apphud.setUIDelegate(self); | ||
} | ||
|
||
@objc(setApphudProductIdentifiers:withResolve:withReject:) | ||
public func setApphudProductIdentifiers(ids: NSArray, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void { | ||
self.productIdentifiers = ids as! [String]; | ||
resolve(self.productIdentifiers); | ||
} | ||
|
||
override func supportedEvents() -> [String]! { | ||
return [ | ||
"apphudDidFetchStoreKitProducts", | ||
"apphudDidChangeUserID", | ||
"apphudSubscriptionsUpdated", | ||
"apphudNonRenewingPurchasesUpdated", | ||
"apphudProductIdentifiers", | ||
"apphudDidPurchase", | ||
"apphudWillPurchase", | ||
"apphudDidFailPurchase", | ||
"apphudDidSelectSurveyAnswer" | ||
] | ||
} | ||
} | ||
|
||
extension ApphudSdkEvents: ApphudDelegate { | ||
|
||
func apphudDidFetchStoreKitProducts(_ products: [SKProduct]) { | ||
let result:[NSDictionary] = products.map{ (product) -> NSDictionary in | ||
return DataTransformer.skProduct(product: product); | ||
} | ||
self.sendEvent(withName: "apphudDidFetchStoreKitProducts", body: result); | ||
} | ||
|
||
func apphudDidChangeUserID(_ userID: String) { | ||
self.sendEvent(withName: "apphudDidChangeUserID", body: userID); | ||
} | ||
|
||
func apphudSubscriptionsUpdated(_ subscriptions: [ApphudSubscription]) { | ||
let result:[NSDictionary] = subscriptions.map{ (subscription) -> NSDictionary in | ||
return DataTransformer.apphudSubscription(subscription: subscription); | ||
} | ||
self.sendEvent(withName: "apphudSubscriptionsUpdated", body: result); | ||
} | ||
|
||
func apphudNonRenewingPurchasesUpdated(_ purchases: [ApphudNonRenewingPurchase]) { | ||
let result:[NSDictionary] = purchases.map{ (purchase) -> NSDictionary in | ||
return DataTransformer.nonRenewingPurchase(nonRenewingPurchase: purchase); | ||
} | ||
self.sendEvent(withName: "apphudNonRenewingPurchasesUpdated", body: result); | ||
} | ||
|
||
func apphudProductIdentifiers() -> [String] { | ||
return self.productIdentifiers; | ||
} | ||
} | ||
|
||
extension ApphudSdkEvents: ApphudUIDelegate { | ||
|
||
func apphudDidPurchase(product: SKProduct, offerID: String?, screenName: String) { | ||
self.sendEvent(withName: "apphudDidPurchase", body: [ | ||
"product": DataTransformer.skProduct(product: product), | ||
"offerId": offerID as Any, | ||
"screenName": screenName | ||
]); | ||
} | ||
|
||
func apphudWillPurchase(product: SKProduct, offerID: String?, screenName: String) { | ||
self.sendEvent(withName: "apphudWillPurchase", body: [ | ||
"product": DataTransformer.skProduct(product: product), | ||
"offerId": offerID as Any, | ||
"screenName": screenName | ||
]); | ||
} | ||
|
||
func apphudDidFailPurchase(product: SKProduct, offerID: String?, errorCode: SKError.Code, screenName: String) { | ||
self.sendEvent(withName: "apphudWillPurchase", body: [ | ||
"product": DataTransformer.skProduct(product: product), | ||
"offerId": offerID as Any, | ||
"screenName": screenName, | ||
"errorCode": errorCode.rawValue | ||
]); | ||
} | ||
|
||
func apphudDidSelectSurveyAnswer(question: String, answer: String, screenName: String) { | ||
self.sendEvent(withName: "apphudDidSelectSurveyAnswer", body: [ | ||
"question": question, | ||
"answer": answer, | ||
"screenName": screenName | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// SKProductDictionary.swift | ||
// ApphudSDK | ||
// | ||
// Created by Alexandr Makarov on 4/8/21. | ||
// | ||
|
||
import Foundation | ||
import StoreKit | ||
import ApphudSDK | ||
|
||
public class DataTransformer { | ||
public static func skProduct(product: SKProduct) -> NSDictionary { | ||
return [ | ||
"id": product.productIdentifier, | ||
"price": product.price, | ||
"regionCode": product.priceLocale.regionCode as Any, | ||
"currencyCode": product.priceLocale.currencyCode as Any, | ||
]; | ||
} | ||
|
||
public static func apphudSubscription(subscription: ApphudSubscription?) -> NSDictionary { | ||
var result:NSDictionary = NSDictionary(); | ||
if (subscription != nil) { | ||
result = [ | ||
"productId": subscription!.productId as Any, | ||
"expiresDate": subscription!.expiresDate.timeIntervalSince1970 as Any, | ||
"startedAt": subscription!.startedAt.timeIntervalSince1970 as Any, | ||
"canceledAt": subscription?.canceledAt?.timeIntervalSince1970 as Any, | ||
"isInRetryBilling": subscription!.isInRetryBilling as Any, | ||
"isAutorenewEnabled": subscription!.isAutorenewEnabled as Any, | ||
"isIntroductoryActivated": subscription!.isIntroductoryActivated as Any, | ||
"isActive": subscription!.isActive() as Any, | ||
"status": subscription!.status.rawValue as Any, | ||
"isLocal": subscription!.isLocal as Any, | ||
"isSandbox": subscription!.isSandbox as Any | ||
] | ||
} | ||
return result; | ||
} | ||
|
||
public static func nonRenewingPurchase(nonRenewingPurchase: ApphudNonRenewingPurchase?) -> NSDictionary { | ||
var result:NSDictionary = NSDictionary(); | ||
if (nonRenewingPurchase != nil) { | ||
result = [ | ||
"productId": nonRenewingPurchase!.productId as Any, | ||
"purchasedAt": nonRenewingPurchase!.purchasedAt.timeIntervalSince1970 as Any, | ||
"canceledAt": nonRenewingPurchase?.canceledAt?.timeIntervalSince1970 as Any, | ||
"isLocal": nonRenewingPurchase!.isLocal as Any, | ||
"isSandbox": nonRenewingPurchase!.isSandbox as Any | ||
] | ||
} | ||
return result; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,5 @@ Pod::Spec.new do |s| | |
|
||
|
||
s.dependency "React-Core" | ||
s.dependency "ApphudSDK" | ||
s.dependency "ApphudSDK", "1.2" | ||
end |
Oops, something went wrong.