专业java、php、iOS、C++、网页设计、平面设计、网络营销、游戏开发、前端与移动开发培训机构

发布不带图片的微博

  • 发布不带图片的微博,接口文档:http://open.weibo.com/wiki/2/statuses/update
  • HMStatusListViewModel 里面 添加 sendStatus 类方法

    /**
    发布微博, 连续两次发布的微博不可以重复
    parameter status:             微博内容
    parameter sendStatusCallBack: 回调
    */
    func sendStatus(status: String, sendStatusCallBack: @escaping (Error?) -> ()) {
      // 判断token
      guard let access_token = HMUserAccountViewModel.shared.userAccount?.access_token else {
          print("token为空")
          return
      }
    
      // 参数
      let parameters = [
          "access_token": access_token,
          "status": status
      ]
    
      // url
      let urlString = "https://api.weibo.com/2/statuses/update.json"
    
      // 发送请求
      HMNetworkTool.shared.afnManager.post(urlString, parameters: parameters, progress: nil, success: { (_, result) -> Void in
          sendStatusCallBack(nil)
      }) { (_, error) -> Void in
          sendStatusCallBack(error)
      }
    }
    
  • HMComposeViewController 里面的 sendStatus 方法里面 发送微博

    func sendStatus() -> Void {
      // 获取要发布的内容
      let status = textView.emoticonText()
    
      // 微博长度
      let length = status.characters.count
    
      // 计算文本剩余长度
      let leftLength = statusMaxLength - length
      if leftLength < 0 {
          SVProgressHUD.showError(withStatus: "文字超出长度")
          return
      }
    
      SVProgressHUD.showInfo(withStatus: "正在发布微博")
    
      HMStatusListViewModel.shared.sendStatus(status: status) { (error: Error?) in
          if error != nil {
              SVProgressHUD.showError(withStatus: "发布微博失败")
              print("error \(error)")
              return
          }
    
          // 发布微博成功了
          SVProgressHUD.showSuccess(withStatus: "发布微博成功")
          DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2, execute: { 
              self.close()
          })
      }
    }
    

results matching ""

    No results matching ""