import UIKit
import UserNotifications @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if #available(iOS 10, *){
iOS8Later()
return true
} if #available(iOS 8, *){
iOS10Later()
return true
}
early() return true
} ///请求完成后会调用把获取的deviceToken返回给我们
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { testStringToData() //deviceToken = 32 bytes
print("deviceToken = \(deviceToken)") //FIXME:打印推送64位token
print(deviceToken.map { String(format: "%02.2hhx", arguments: [$0]) }.joined() , "推送 deviceToken" )
} func testStringToData(){
let testStr = "莎莎哈"
let testData = testStr.data(using: String.Encoding.utf8)
let newTestStr = String(data: testData ?? Data(), encoding: String.Encoding.utf8)
print("======", testStr, testData, newTestStr)
} } extension AppDelegate{ func early(){
let type = UIRemoteNotificationType.alert.rawValue | UIRemoteNotificationType.badge.rawValue | UIRemoteNotificationType.sound.rawValue
UIApplication.shared.registerForRemoteNotifications(matching: UIRemoteNotificationType(rawValue: type))
} func iOS8Later(){
let type = UIUserNotificationType.badge.rawValue | UIUserNotificationType.alert.rawValue | UIUserNotificationType.sound.rawValue
//请求授权
let set = UIUserNotificationSettings(types: UIUserNotificationType(rawValue: type), categories: nil) UIApplication.shared.registerUserNotificationSettings(set) //需要通过设备UUID 和APP bundle ID 发送请求,获取deviceToken
UIApplication.shared.registerForRemoteNotifications()
} func iOS10Later(){
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: UNAuthorizationOptions.alert) { (isSucceseed: Bool, error:Error?) in if isSucceseed == true{
print( "成功")
}else{
print( "失败")
print("error = \(error)")
}
}
UIApplication.shared.registerForRemoteNotifications()
}
} extension AppDelegate: UNUserNotificationCenterDelegate{ }

  

Swift3.1的DeviceToken打印的是32Bytes
https://www.jianshu.com/p/fed585eef7c1

swift4.2 打印devicetoken的更多相关文章

  1. swift4.2 打印所有系统字体

    func showAllFonts(){ let familyNames = UIFont.familyNames var index:Int = 0 for familyName in family ...

  2. 推送测试,生产环境无法打印log获取deviceToken,可以通过弹窗获取deviceToken

    z- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:( ...

  3. Swift4 - GCD的使用

    Swift4 - GCD的使用 2018年03月30日 17:33:27 Longshihua 阅读数:1165 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csd ...

  4. ASP.NET MVC5+EF6+EasyUI 后台管理系统(55)-Web打印

    系列目录 前言 1.本次主要弥补工作流,用户表单数据的打印 2.使用JQprint做为web打印插件 3.兼容:FireFox,Chrome,IE. 4.没有依赖也没有配置,使用简单 代码下载:htt ...

  5. C#中5步完成word文档打印的方法

    在日常工作中,我们可能常常需要打印各种文件资料,比如word文档.对于编程员,应用程序中文档的打印是一项非常重要的功能,也一直是一个非常复杂的工作.特别是提到Web打印,这的确会很棘手.一般如果要想选 ...

  6. 开源免费且稳定实用的.NET PDF打印组件itextSharp(.NET组件介绍之八)

    在这个.NET组件的介绍系列中,受到了很多园友的支持,一些园友(如:数据之巅. [秦时明月]等等这些大神 )也给我提出了对应的建议,我正在努力去改正,有不足之处还望大家多多包涵.在传播一些简单的知识的 ...

  7. Ajax使用WCF实现小票pos机打印源码

    通过ajax跨域方式调用WCF服务,实现小票pos机的打印,源码提供web方式,客户端方式测试,服务驻留右侧底部任务栏,可控制服务开启暂停,用户可自定义小票打印模板,配合零售录入. qq  22945 ...

  8. Jqprint实现页面打印

    好些项目需要实现页面打印,特别是一些后台管理类系统,下面介绍一款轻量级的打印插件: 1.实现页面打印要引入jQuery和Jqprint.点击下载Jqprint插件 <script languag ...

  9. Android连接网络打印机进行打印

    首先这是网络打印工具类,通过Socket实现,多说一句,网络打印机端口号一般默认的是9100 package com.Ieasy.Tool; import android.annotation.Sup ...

随机推荐

  1. spring-mvc.xml与spring-mybatis.xml配置文件中命名空间问题

    首先贴出配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...

  2. css- 范围选择

    1.子元素范围选择 举例 .iconList_wr li:nth-child(n + 1):nth-child(-n + 4) { margin-right: 0.6rem; } .iconList_ ...

  3. 尚硅谷redis学习2-redis的安装和HelloWorld

    Reids: remote dictionary server redis特点:支持持久化,支持复杂数据类型,支持备份 下载: 解压: 执行make, make install 可能会需要安装make ...

  4. Zookeeper 在Linux系统的安装

    注册中心Zookeeper 官方推荐使用 zookeeper 注册中心.注册中心负责服务地址的注册与查找,相当于目录服务,服务提供者和消费者只在启动时与注册中心交互,注册中心不转发请求,压力较小. Z ...

  5. java.util.Arrays$ArrayList addAll报错

    执行下面代码时报错: List<String> centerList = WebConstants.SUPPORT_BIG_CENTERS_LIST; // WebConstants.SU ...

  6. How to Pronounce the Idiom: ‘Out Like a Light’

    How to Pronounce the Idiom: ‘Out Like a Light’ Share Tweet Share Tagged With: Idioms English is full ...

  7. [PHP]更新中间关联表数据的两种思路

    ---------------------------------------------------------------------------------------------------- ...

  8. Android DevArt2:Android 5.0下 Dialog&AlertDialog 并不会影响Activity的生命周期

    先给出结论:Dialog和AlertDialog并不会影响到Activity的生命周期,但会影响到Activity的优先级. 核心代码: onCreated中: Resources resources ...

  9. springboot 整合redis redis工具类

    一步 : pom中引入相关依赖 <!-- 引入 redis 依赖 --> <dependency> <groupId>org.springframework.boo ...

  10. JAVA程序员常用英语

    JAVA程序员常用英语 干程序员这行实在是离不开英语,干程序员是一项很辛苦的工作,要成为一个高水平的程序员尤为艰难.这是因为计算机软件技术更新的速度越来越快,而这些技术大多来源于英语国家,我们在引进这 ...