swift4.2 打印devicetoken
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的更多相关文章
- swift4.2 打印所有系统字体
func showAllFonts(){ let familyNames = UIFont.familyNames var index:Int = 0 for familyName in family ...
- 推送测试,生产环境无法打印log获取deviceToken,可以通过弹窗获取deviceToken
z- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:( ...
- Swift4 - GCD的使用
Swift4 - GCD的使用 2018年03月30日 17:33:27 Longshihua 阅读数:1165 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csd ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(55)-Web打印
系列目录 前言 1.本次主要弥补工作流,用户表单数据的打印 2.使用JQprint做为web打印插件 3.兼容:FireFox,Chrome,IE. 4.没有依赖也没有配置,使用简单 代码下载:htt ...
- C#中5步完成word文档打印的方法
在日常工作中,我们可能常常需要打印各种文件资料,比如word文档.对于编程员,应用程序中文档的打印是一项非常重要的功能,也一直是一个非常复杂的工作.特别是提到Web打印,这的确会很棘手.一般如果要想选 ...
- 开源免费且稳定实用的.NET PDF打印组件itextSharp(.NET组件介绍之八)
在这个.NET组件的介绍系列中,受到了很多园友的支持,一些园友(如:数据之巅. [秦时明月]等等这些大神 )也给我提出了对应的建议,我正在努力去改正,有不足之处还望大家多多包涵.在传播一些简单的知识的 ...
- Ajax使用WCF实现小票pos机打印源码
通过ajax跨域方式调用WCF服务,实现小票pos机的打印,源码提供web方式,客户端方式测试,服务驻留右侧底部任务栏,可控制服务开启暂停,用户可自定义小票打印模板,配合零售录入. qq 22945 ...
- Jqprint实现页面打印
好些项目需要实现页面打印,特别是一些后台管理类系统,下面介绍一款轻量级的打印插件: 1.实现页面打印要引入jQuery和Jqprint.点击下载Jqprint插件 <script languag ...
- Android连接网络打印机进行打印
首先这是网络打印工具类,通过Socket实现,多说一句,网络打印机端口号一般默认的是9100 package com.Ieasy.Tool; import android.annotation.Sup ...
随机推荐
- WDA-6-EP系统管理/内容管理/用户管理
主要是将EP端系统管理.内容管理.用户管理相关内容进行下梳理. 1.系统管理 1.1系统前景 1.2对象锁定 解锁相关对象 2.内容管理 2.1基本介绍 门户桌面-组件: 四大内容: iViews:可 ...
- java配置slf4j日志系统
首先要导入的包: import: 每个类中加入下面,其中 RdiFtpDownload.class 是当前的类名.class 然后就可以打日志了: 配置 log4j.properties log4j. ...
- E_FAIL (0x80004005) MachineWrap
下载VirtualBox-4.3.12-93733-Win.exe,下载地址:http://download.virtualbox.org/virtualbox/4.3.12/
- Oracle数据文件迁移到裸设备
本文主要描述如何将Oracle表空间的文件系统形式的数据文件迁移到LV裸设备上. 前提条件 1.oracle运行正常. 2.已使用LVM命令规划好LV文件.如/dev/vgoracle/lvdatat ...
- overload重载
方法的重载 /** * 重载 overload * @author Administrator *同一个类,同一个方法 *不同:参数列表不同(类型,个数,顺序) 只和 参数列表有关 * 跟 返回值 和 ...
- 全局异常 同时ajax或是web跳转
F8功能强大 在java代码debug的时候,F8键可直接跳到下一个类中.免去下一步 只用把之前两种方式合并即可,就是在exception包中不要ajax的异常,将其放入到web异常中,用if ...
- C# 集合转换为DataTable
该类就用了几个类型,如int,int?,string,所以其它类型就先没管. 用到的类: public class tb_Projects { public int ProID { get; set; ...
- 八皇后问题-dfs
一.题意解析 国际象棋中的皇后,可以横向.纵向.斜向移动.如何在一个8X8的棋盘上放置8个皇后,使得任意两个皇后都不在同一条横线.竖线.斜线方向上?八皇后问题是一个古老的问题,于1848年由一位国际象 ...
- js 提示条
js: var Persen = { timeUptopBar:function(fun) { var obj = $('.top-alert'); obj.fadeOut(1500,function ...
- JVM不稳定参数
-XX 参数被称为不稳定参数,之所以这么叫是因为此类参数的设置很容易引起JVM 性能上的差异,使JVM 存在极大的不稳定性.当然这是在非合理设置的前提下,如果此类参数设置合理讲大大提高JVM 的性能及 ...