Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nianshaofanghua opened this issue Jul 5, 2021 · 2 comments

Comments

@nianshaofanghua
Copy link

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

@eatbye
Copy link

eatbye commented Jul 5, 2021

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

@shuigesuntao
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants