什么是 Monetizr?
Monetizr 是一个为游戏开发者提供的现成平台,使他们能够在游戏 UI 中直接出售或赠送游戏配件。您可以在游戏中使用此 SDK,让玩家在游戏中购买商品或领取礼品。所有使用 Monetizr 下单的订单将自动启动履约和配送。更多信息:[https://docs.themonetizr.com/docs/get-started](https://docs.themonetizr.com/docs/get-started)
Monetizr iOS SDK
Monetizr iOS SDK 是一个插件,内置以下功能
- 向最终用户提供展示图片轮播和全屏图片的功能;
- 用于描述的 HTML 文本;
- 允许最终用户选择产品变体选项;
- 显示实价或游戏货币的价格(包括折扣);
- 结账和支付支持;
- 可选的 Apple Pay 支持。
Monetizr 在背后使用 oAuth 2 验证所有与支付和订单相关的进程。SDK 负责管理 oAuth 2。要使用 SDK 并连接到 Monetizr 服务器,您只需要一个 API 密钥。可以通过 Monetizr Web 控制台[https://app.themonetizr.com/](https://app.themonetizr.com/)检索该 API 密钥。API 是公开双向的,它不会暴露任何有用的信息,但您应该意识到这一点。
请阅读 Monetizr 的 iOS 文档以获取更多信息。[https://docs.themonetizr.com/docs/ios](https://docs.themonetizr.com/docs/ios)
安装
需要 iOS 11.0+
依赖关系
- Alamofire - Swift中的优雅HTTP网络编程;
- AlamofireImage - Alamofire的图像组件库;
- ImageSlideshow - Swift图像幻灯片;
- Stripe - 允许用户使用Apple Pay购买产品;
- McPicker - UIPickerView的现成解决方案。
选项1(推荐)
CocoaPods
pod 'Monetizr', '~> 3.5'
选项2
将“Monetizr-SDK”文件夹复制到您的项目中,并解决依赖关系。在您的项目中导入“Monetizr”
import Monetizr
在您的应用中使用库
要使用SDK,您需要一个API密钥。为了测试目的,您可以使用公开测试密钥4D2E54389EB489966658DDD83E2D1
。
在applicationDidFinishLaunching(_:)中,使用API密钥进行初始化
Monetizr.shared.token = "4D2E54389EB489966658DDD83E2D1"
要在一个优惠视图中显示产品,您需要调用特定的product_tag。产品标签代表了一个特定的产品,它们在Web控制台中管理。为了测试目的,您可以使用公开测试产品T-shirt
。
在您的应用中显示优惠视图
Monetizr.shared.showProduct(tag: "T-shirt", playerID: String(Optional) presenter: UIViewController?, presentationStyle: UIModalPresentationStyle?) { success, error, product, uniqueID in ()}
如果您选择在SDK中提供的优惠视图中显示产品,您应提供呈现视图和呈现样式。如果没有提供呈现样式,它将默认为iOS 13.x的UIModalPresentationStyle.automatic
或其他iOS版本的UIModalPresentationStyle.overCurrentContext
。
实现MonetizrDelegate
来接收Monetizr中事件的通知
- 购买时展示优惠视图
func monetizrPurchase(tag: String?, uniqueID: String?)
可选设置
Apple Pay
要在applicationDidFinishLaunching(_:)方法中使用Apple Pay进行支付,请设置您的商户ID
Monetizr.shared.setApplePayMerchantID(id: String)
此外,您还可以重写默认的支付接收者名称(应用程序包名称),该名称用于Apple支付表单。这会更改最终用户在其收据上看到的显示的支付接收者。
Monetizr.shared.setCompanyName(companyName: String)
了解更多关于为Monetizr集成设置Apple Pay的方法,请点击此处。
主题
默认设置为>.system。您可以自定义Offer View主题
Monetizr.shared.setTheme(theme: ProductViewControllerTheme)
直到iOS13版本的.system使用带globalTint元素的浅色主题。iOS13+版本的.system根据用户的偏好设置使用暗/浅色模式并适应用户的选择。
.black - 在所有iOS版本和模式下,所有版本和模式下都是设置为带有红色元素的暗色调。
Monetizr.shared自定义
创建ProductViewController
func productViewForProduct(product: Product, tag: T-shirt, playerID: String(Optional)) -> ProductViewController
显示ProductView
func presentProductView(productViewController: ProductViewController, presenter: UIViewController, presentationStyle: UIModalPresentationStyle)
为产品变体进行结账。
func checkoutSelectedVariantForProduct(selectedVariant: PurpleNode, tag: T-shirt, shippingAddress: CheckoutAddress(Optional) completionHandler: @escaping (Bool, Error?, Checkout?) -> Void)
更新结账
func updateCheckout(request: UpdateCheckoutRequest, completionHandler: @escaping (Bool, Error?, CheckoutResponse?) -> Void)
领取订单
func claimOrder(shippingLine: CheckoutData?, player_id: String, price: String, completionHandler: @escaping (Bool, Error?, Claim?) -> Void)
使用Apple Pay结账
Monetizr.shared.buyWithApplePay(selectedVariant: selectedVariant!, tag: T-shirt!, presenter: UIViewController) { success, error in ()}