TDShopSDK 1.1.0

TDShopSDK 1.1.0

kcheng-verbose 维护。



 
依赖关系
Alamofire~> 4.8.0
SDWebImage~> 5.0
Bugsnag>= 0
 

TDShopSDK 1.1.0

  • 作者
  • kcheng

TDShopSDK iOS

README: 英文 | 中文

安装

从 CocoaPods 安装

pod 'TDShopSDK'

示例(Swift)

"import TDShopSDK"

1.初始化 SDK

let config = TDConfig.config(appkey: "your appKey") { (isInitSuccess,errMsg) in
}
// You can show TDShopSDK's log ,if you set isDebug true.
config.isDebug = true
TDShopSDK.sdkInitialize(config: config)

2.URL SCHEME

步骤1:将TDShopSDK方案添加到Info.plist文件中

tdshop方案

步骤2:处理应用打开URL消息

func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
     return TDShopSDK.handleOpenUrl(url: url)
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
     return TDShopSDK.handleOpenUrl(url: url)
}

步骤3:使用DemoLink进行测试

tdshop://mytdshop.net/195221EF4498F6F0E1CC10C852843F2643C4168F181E443552C442C50939A437

如果成功,SDK将打开一个ViewController,显示谷歌页面!

3.TDIconView

TDIconView需要一个适当的宽高比(宽:高 1:1)

let WH:CGFloat = 100
let iconView = TDIconView.init(frame: CGRect.init(x: 0, y: 0, width: WH, height: WH), viewId: "test_ios_icon_001")
self.view.addSubview(iconView)

在viewWillAppear中添加以下代码

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.iconView.handleWhenViewAppear()
}

4.TDBannerView

TDBannerView 需要合适的长宽比(宽:高 720:372)

let W:CGFloat = 300
let H:CGFloat = W * 372/720.0
let bannerView = TDBannerView.init(frame: CGRect.init(x: 0, y: 0, width: W, height: H), viewId: "test_ios_banner_001")
self.view.addSubview(bannerView)

在viewWillAppear方法中添加以下代码

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.bannerView.handleWhenViewAppear()
}

5.TDCustomView

1.创建 TDCustomView 的子类。

class CustomView: TDCustomView {
  //init
  override init(viewId: String, tags: [String]?) {
      super.init(viewId: viewId, tags: tags)
   }
   //handle click event
   @objc func click(button:UIButton){
        super.handleViewDidClick(button.tag)
    }
   func setupView(resources:[TDAdResourcesModel]) {
        //Creat your custom view 
   }
}

2.获取广告资源,然后配置自定义视图。

TDShopSDK.getAdResourcesInfo(placementId: "placementId", tags: ["hat"]) { (resources) in
            
  self.customView = CustomView.init(viewId: self.placementIdTF.text ?? "", tags: tags2)
  self.customView?.frame = CGRect.init(x: 10, y: currY, width: UIScreen.main.bounds.size.width-20, height: 100)
  self.customView?.setupView(resources: resources)
  self.customView?.handleWhenViewAppear()
  self.view.addSubview(self.customView!)
}

3.在视图出现时调用 handleWhenViewAppear

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.customView?.handleWhenViewAppear()
}

6.配置本地推送服务器。

步骤1:注册本地推送服务器

if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().delegate = self
}

步骤2:处理接收本地推送通知(SDK将适时推送某些本地推送通知。)

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
    if TDShopSDK.canHandleLocalPushNoti(info: notification.request.content.userInfo) {
        completionHandler([.alert])
    }
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  TDShopSDK.handleLocalPushNoti(info: response.notification.request.content.userInfo)
  completionHandler()
}