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. java实现解压zip文件,(亲测可用)!!!!!!

    项目结构: Util.java内容: package com.cfets.demo; import java.io.File; import java.io.FileOutputStream; imp ...

  2. hadoop-1

    结合其他文章 http://weixiaolu.iteye.com/blog/1504898 https://www.cnblogs.com/dycg/p/3934394.html https://b ...

  3. Delphi FrieDAC 大数据处理

    Delphi FrieDAC 大数据处理 大数据处理, 要用到Array DML 插入数据 先要设置插入的数据量 FQuery1.Params.ArraySize := 1000; for index ...

  4. getVisibleSize,getWinSize,getFrameSize,getViewPortRect

    cc.director.getVisibleSize();//获取运行场景的可见大小 cc.director.getWinSize();//获取视图的大小,以点为单位 cc.director.getW ...

  5. oc字符串与c字符串转换和拷贝

    // Helper method to create C string copy NSString* MakeNSString (const char* string) { if (string) { ...

  6. PostgresQL 中有没有rownum这样的,显示结果集的序号

    select * from (select row_number() over() as rownum,tablename from pg_tables) t where rownum<10;

  7. English: How to Pronounce R [ɹ] Consonant

    English: How to Pronounce R [ɹ] Consonant Share Tweet Share Tagged With: Most Popular, Sound How-To ...

  8. redisclient can not connect

    假如采用传统请执行一下命令: systemctl stop firewalld systemctl mask firewalld 并且安装iptables-services: yum install ...

  9. Linux tr命令使用方法

    tr命令主要用于删除文件中控制字符或进行字符转换.本文主要介绍tr命令的基本语法和使用实例. tr基本语法 tr命令格式:tr [ -d ] [ -c ] [ -s ] [ 字符串1 ] [ 字符串2 ...

  10. servlet(2)response常用方法

    详细的response 学习笔记是: 输出到前台的的方法 1:使用OutputStream流向客户端浏览器输出中文数据 2:使用PrintWriter流向客户端浏览器输出中文数据 3:使用Output ...