跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 请教下 iOS 推送 AppDelegate. Swift 该怎么写,或者缺少了什么步骤
未分類
18 4 月 2021

请教下 iOS 推送 AppDelegate. Swift 该怎么写,或者缺少了什么步骤

请教下 iOS 推送 AppDelegate. Swift 该怎么写,或者缺少了什么步骤

資深大佬 : LollipopKit 3

项目是使用的 flutter,第一次接触原生 ios native,请教各位。

已经进行了的操作:
1 、apple 开发者账户网页添加了 push notification 证书
2 、xcode 里 runner target 的 capability 也打开了推送
3 、如下修改了 AppDelegate.swift (参考的官方文档)

但是真机测试并没有 print 出 token 值,就很疑惑,想请教是不是缺少了什么步骤,还是 AppDelegate.swift 写错了

import UIKit import Flutter  @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate {     override func application(_ application: UIApplication,                                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?     ) -> Bool {         UIApplication.shared.registerForRemoteNotifications()         GeneratedPluginRegistrant.register(with: self)         return super.application(application, didFinishLaunchingWithOptions: launchOptions)     }          override func application(_ application: UIApplication,                                 didRegisterForRemoteNotificationsWithDeviceToken                                 deviceToken: Data) {         print(deviceToken)         sendDeviceTokenToServer(token: deviceToken)     } }  func sendDeviceTokenToServer(token: Data) {     let url = URL(string: "https://push.example.com/ios?token=" + String(decoding: token, as: UTF8.self))!      let task = URLSession.shared.dataTask(with: url) {(data, response, error) in         guard let data = data else { return }         print(String(data: data, encoding: .utf8)!)     }      task.resume() } 

大佬有話說 (1)

  • 資深大佬 : frqk

    没有 requestAuthorization 吧

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具