zileyuan / umeng_analytics_push

Umeng Analytics&Push Flutter Plugins
MIT License
30 stars 21 forks source link

iOS要怎么获取devtoken 现在能在log中看到 但是下面代码获取不到 #34

Open nianshaofanghua opened 3 years ago

nianshaofanghua commented 3 years ago

/// get DeviceToken [DeviceToken] static Future<String?> deviceToken() async { Map<String, dynamic> args = {}; return _methodChannel.invokeMethod('deviceToken', args); }

eatbye commented 3 years ago

我是修改了iOS代码,增加didRegisterForRemoteNotificationsWithDeviceToken方法,在这个方法中获取deviceToken,将值写入userdefault。

shuigesuntao commented 3 years ago

放AppDelegate.swift里

override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
      let deviceTokenStr = [UInt8](deviceToken).map{String(format: "%02x", $0)}.joined()
      NSLog("deviceToken:-------->  " + deviceTokenStr)
      UserDefaults.standard.set(deviceTokenStr, forKey: "push_device_token")
   }