umeng_analytics_push icon indicating copy to clipboard operation
umeng_analytics_push copied to clipboard

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

Open nianshaofanghua opened this issue 4 years ago • 2 comments

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

nianshaofanghua avatar Jul 05 '21 09:07 nianshaofanghua

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

eatbye avatar Jul 05 '21 10:07 eatbye

放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")
   }

shuigesuntao avatar Aug 30 '21 08:08 shuigesuntao