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. Linux下Mongodb安装和启动配置 原

    1.安装 略 2.配置 01.mkdir /usr/local/mongodb/data 0.touch /usr/local/mongodb/logs 03.cd /usr/local/mongod ...

  2. Python3.7中urllib.urlopen 报错问题

    import urllib web = urllib.urlopen('https://www.baidu.com') f = web.read() print(f) 报错: Traceback (m ...

  3. Linux:结束线程的三种方式

    一般情况下,线程终止后,其终止状态一直保留到其它线程调用pthread_join获取它的状态为止.但是线程也可以被置为detach状态,这样的线程一旦终止就立刻回收它占用的所有资源,而不保留终止状态. ...

  4. Linux:使用互斥量进行线程同步

    基础知识 同步概念 所谓同步,即同时起步,协调一致.不同的对象,对"同步"的理解方式略有不同.如,设备同步,是指在两个设备之间规定一个共同的时间参考:数据库同步,是指让两个或多个数 ...

  5. JS实现简单的运行代码 & 侧边广告

    /* JS实现简单的运行代码功能 */<!doctype html> <html> <head> <meta charset="utf-8" ...

  6. 第五次Scrum冲刺

    第五次Scrum冲刺 1.成员今日完成情况 队员 今日完成任务 刘佳 前端初步构建 李佳 后端设计初级阶段 周世元 数据设计 杨小妮 博客编写 许燕婷 管理团队当日及次日任务 陈水莲 测试矩阵用例设计 ...

  7. 问题描述: fatal error: 'XCTest/XCTest.h' file not found

    #import 解决方法:在报错的Target中的Building settings中FRAMEWORK_SEARCH_PATHS添加$(PLATFORM_DIR)/Developer/Library ...

  8. set 转 enumeration

  9. 吴裕雄 09-MySQL删除数据表

    以下为删除MySQL数据表的通用语法:DROP TABLE table_name; DROP TABLE runoob_tbl; 使用PHP脚本删除数据表PHP使用 mysqli_query 函数来删 ...

  10. SSM商城项目(一)

    1. 学习计划 1.电商行业的背景. 2.宜立方商城介绍 3.宜立方商城的系统架构 a) 功能介绍 b) 架构讲解 4.工程搭建-后台工程 a) 使用maven搭建工程 b) 使用maven的tomc ...