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 ...
随机推荐
- Redis-stat 的安装与使用
一.ruby源码安装 下载最新版的 Ruby 压缩文件.请点击这里下载. 下载 Ruby 之后,解压到新创建的目录下: $ tar -xvzf ruby-2.2.3.tgz $ cd ruby-2.2 ...
- ReactiveX 学习笔记(18)使用 RxJS + Angular 调用 REST API
JSON : Placeholder JSON : Placeholder (https://jsonplaceholder.typicode.com/) 是一个用于测试的 REST API 网站. ...
- Go语言学习笔记(2)
数组 var a [2]string a[0] = "Hello" a[1] = "World" primes := [6]int{2, 3, 5, 7, 11 ...
- 直接在浏览器运行jsx及高版本的js代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- Python读写文件基础.py
基本函数 定义 python内置了open()函数来操作文件,open()函数的定义为: open(file, mode='r', buffering=-1, encoding=None, error ...
- ArcMap导入图层出现General function failure问题 [转]
ArcMap导入图层出现General function failure问题 [转] Link: http://www.cnblogs.com/angelx/p/3391967.html 问题描述 ...
- C++ 关于 CMFCPropertyGridCtrl 的使用方法 之二 (原创)
接上一节所讲,这一节咱们重点讲一下CMFCPropertyGridCtrl 所支持的数据表格的建立过程 在上一节中,咱们已经了解到了 CMFCPropertyGridCtrl 是要用到实例函数:Ad ...
- C# 根据Excel生成树
需求: 根据Excel生成树,Excel的某些节点为属性节点, 如: 列(桩号.构件编码.测试属性1) 是列(分项工程名称) 的属性,非节点. 列(桩号.构件编码.测试属性1) 以属性的方式存在 导入 ...
- C# Excel转换为Json
demo:https://files.cnblogs.com/files/guxingy/Excel%E8%BD%AC%E6%8D%A2%E4%B8%BAJson%E5%AF%B9%E8%B1%A1. ...
- vue如果是首页了 不让其后退
history.pushState(null, null, document.URL); //首页加载时候先置空 window.addEventListener('popstate', functio ...