|
@@ -7,18 +7,37 @@
|
|
|
//
|
|
|
|
|
|
import UIKit
|
|
|
+import SwiftyJSON
|
|
|
|
|
|
//MARK: - UMeng
|
|
|
-let kUMengAppKey = "5c984a7f0cafb2332300000f"
|
|
|
-let kUMengAppSecret = "lpx7kstlnlrxmimo5gfyzvtscrtguhw8"
|
|
|
+
|
|
|
+let kUMengAppKey = "5d4d38ce0cafb2131c00041c"
|
|
|
+let kUMengAppSecret = "mllaspth0pdgnhdm02uvkppby3isxxex"
|
|
|
+//彩虹星球
|
|
|
+//let kUMengAppKey = "5c984a7f0cafb2332300000f"
|
|
|
+//let kUMengAppSecret = "lpx7kstlnlrxmimo5gfyzvtscrtguhw8"
|
|
|
|
|
|
//MARK: - QQ跟安卓用同一个
|
|
|
-let kQQAppKey = "101565722"
|
|
|
-let kQQAppSecret = "dfe6f96762ed0dbc3ad52dc06d0eda9b"
|
|
|
+
|
|
|
+let kQQAppKey = "101742987"
|
|
|
+let kQQAppSecret = "664edcf45543f1958b46f914c03b3ed0"
|
|
|
+//彩虹星球
|
|
|
+//let kQQAppKey = "101565722"
|
|
|
+//let kQQAppSecret = "dfe6f96762ed0dbc3ad52dc06d0eda9b"
|
|
|
|
|
|
//MARK: - 微信
|
|
|
-let kWeiXinAppKey = "wx163e76382d53654b"
|
|
|
-let kWeiXinAppSecret = "1a915228304ea2e45eda9d2af5a64b84"
|
|
|
+let kWeiXinAppKey = "wx0aed0c936870ad29"
|
|
|
+let kWeiXinAppSecret = "6be875a7f04d19bdaeec4c0858886ac6"
|
|
|
+//彩虹星球
|
|
|
+//let kWeiXinAppKey = "wx163e76382d53654b"
|
|
|
+//let kWeiXinAppSecret = "1a915228304ea2e45eda9d2af5a64b84"
|
|
|
+
|
|
|
+//MARK: - 微博
|
|
|
+let kWeiboAppKey = "1960193914"
|
|
|
+let kWeiboAppSecret = "ad525c2e9eb07bb0bc43f998295cfe51"
|
|
|
+//彩虹星球
|
|
|
+//let kWeiboAppKey = "4123861024"
|
|
|
+//let kWeiboAppSecret = "79d36bfe6b75638ece14d5d852e785c4"
|
|
|
|
|
|
|
|
|
public enum ShareType {
|
|
@@ -30,15 +49,8 @@ public enum ShareType {
|
|
|
public var _entity : UMessageRegisterEntity?
|
|
|
|
|
|
public class UMManager: NSObject {
|
|
|
- private static let sharedInstance = UMManager()
|
|
|
- private override init() {} // 私有化init方法
|
|
|
-
|
|
|
- /// 单例
|
|
|
- ///
|
|
|
- /// - Returns: UMShareManager对象
|
|
|
- public class func shared() -> UMManager {
|
|
|
- return sharedInstance
|
|
|
- }
|
|
|
+
|
|
|
+ static let shared : UMManager = UMManager()
|
|
|
|
|
|
/// 友盟初始化
|
|
|
public func initUM(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
|
|
@@ -57,16 +69,16 @@ public extension UMManager {
|
|
|
func common() -> Void {
|
|
|
|
|
|
//将自动采集页面信息
|
|
|
- // MobClick.setAutoPageEnabled(true)
|
|
|
+ MobClick.setAutoPageEnabled(true)
|
|
|
//开发者需要显式的调用此函数,日志系统才能工作
|
|
|
UMCommonLogManager.setUp()
|
|
|
//打开加密传输
|
|
|
UMConfigure.setEncryptEnabled(true)
|
|
|
//设置打开日志
|
|
|
- UMConfigure.setLogEnabled(false)
|
|
|
+ UMConfigure.setLogEnabled(true)
|
|
|
//设置Key
|
|
|
UMConfigure.initWithAppkey(kUMengAppKey, channel: "App Store")
|
|
|
-
|
|
|
+
|
|
|
//开启Crash收集
|
|
|
MobClick.setCrashReportEnabled(true)
|
|
|
//默认为普通应用场景,目前还支持游戏统计场景
|
|
@@ -87,46 +99,49 @@ public extension UMManager {
|
|
|
///推送
|
|
|
func push(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
|
|
|
|
|
|
+ UMessage.openDebugMode(true)
|
|
|
+ UMessage.setBadgeClear(true)//设置是否允许SDK自动清空角标
|
|
|
+ UMessage.setWebViewClassString("UMWebViewController")
|
|
|
+// UMessage.addLaunch() //开屏图
|
|
|
_entity = UMessageRegisterEntity.init()
|
|
|
//type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
|
|
|
_entity?.types = Int(UInt8(UMessageAuthorizationOptions.badge.rawValue)|UInt8(UMessageAuthorizationOptions.alert.rawValue)|UInt8(UMessageAuthorizationOptions.sound.rawValue))
|
|
|
|
|
|
- if #available(iOS 8.0, *) {
|
|
|
- if #available(iOS 10.0, *) {
|
|
|
-
|
|
|
- let action1_ios10 = UNNotificationAction(identifier: "action1_identifier", title: "打开应用", options: UNNotificationActionOptions.foreground)
|
|
|
- let action2_ios10 = UNNotificationAction(identifier: "action2_identifier", title: "忽略", options: UNNotificationActionOptions.foreground)
|
|
|
-
|
|
|
- let category1_ios10 = UNNotificationCategory(identifier: "category1", actions: [action1_ios10,action2_ios10], intentIdentifiers: [], options: UNNotificationCategoryOptions.customDismissAction)
|
|
|
- //UNNotificationCategoryOptionNone
|
|
|
- //UNNotificationCategoryOptionCustomDismissAction 清除通知被触发会走通知的代理方法
|
|
|
- //UNNotificationCategoryOptionAllowInCarPlay 适用于行车模式
|
|
|
- let categories = NSSet(objects: category1_ios10)
|
|
|
- _entity?.categories = (categories as! Set<AnyHashable>)
|
|
|
- UNUserNotificationCenter.current().delegate = self
|
|
|
-
|
|
|
- } else {
|
|
|
- let action1 = UIMutableUserNotificationAction.init()
|
|
|
- action1.identifier = "action1_identifier"
|
|
|
- action1.title = "打开应用"
|
|
|
- action1.activationMode = UIUserNotificationActivationMode.foreground;//当点击的时候启动程序
|
|
|
-
|
|
|
- let action2 = UIMutableUserNotificationAction.init()
|
|
|
- action2.identifier = "action2_identifier"
|
|
|
- action2.title = "忽略"
|
|
|
- action2.activationMode = UIUserNotificationActivationMode.background;//当点击的时候不启动程序,在后台处理
|
|
|
- action2.isAuthenticationRequired = true;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
|
|
|
- action2.isDestructive = true;
|
|
|
-
|
|
|
- let actionCategory1 = UIMutableUserNotificationCategory.init()
|
|
|
- actionCategory1.identifier = "category1"//这组动作的唯一标示
|
|
|
- actionCategory1.setActions([action1,action2], for: UIUserNotificationActionContext.default)
|
|
|
- let categories = NSSet(objects: actionCategory1)
|
|
|
- _entity?.categories = (categories as! Set<AnyHashable>)
|
|
|
+ if #available(iOS 10.0, *) {
|
|
|
+
|
|
|
+ let action1_ios10 = UNNotificationAction(identifier: "action1_identifier", title: "打开应用", options: UNNotificationActionOptions.foreground)
|
|
|
+ let action2_ios10 = UNNotificationAction(identifier: "action2_identifier", title: "忽略", options: UNNotificationActionOptions.foreground)
|
|
|
+
|
|
|
+ let category1_ios10 = UNNotificationCategory(identifier: "category1", actions: [action1_ios10,action2_ios10], intentIdentifiers: [], options: UNNotificationCategoryOptions.customDismissAction)
|
|
|
+ //UNNotificationCategoryOptionNone
|
|
|
+ //UNNotificationCategoryOptionCustomDismissAction 清除通知被触发会走通知的代理方法
|
|
|
+ //UNNotificationCategoryOptionAllowInCarPlay 适用于行车模式
|
|
|
+ let categories = NSSet(objects: category1_ios10)
|
|
|
+ _entity?.categories = (categories as! Set<AnyHashable>)
|
|
|
+ UNUserNotificationCenter.current().delegate = self
|
|
|
+
|
|
|
+ } else {
|
|
|
+ let action1 = UIMutableUserNotificationAction.init()
|
|
|
+ action1.identifier = "action1_identifier"
|
|
|
+ action1.title = "打开应用"
|
|
|
+ action1.activationMode = UIUserNotificationActivationMode.foreground;//当点击的时候启动程序
|
|
|
+
|
|
|
+ let action2 = UIMutableUserNotificationAction.init()
|
|
|
+ action2.identifier = "action2_identifier"
|
|
|
+ action2.title = "忽略"
|
|
|
+ action2.activationMode = UIUserNotificationActivationMode.background;//当点击的时候不启动程序,在后台处理
|
|
|
+ action2.isAuthenticationRequired = true;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
|
|
|
+ action2.isDestructive = true;
|
|
|
+
|
|
|
+ let actionCategory1 = UIMutableUserNotificationCategory.init()
|
|
|
+ actionCategory1.identifier = "category1"//这组动作的唯一标示
|
|
|
+ actionCategory1.setActions([action1,action2], for: UIUserNotificationActionContext.default)
|
|
|
+ let categories = NSSet(objects: actionCategory1)
|
|
|
+ _entity?.categories = (categories as! Set<AnyHashable>)
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
+ //注册通知
|
|
|
UMessage.registerForRemoteNotifications(launchOptions: launchOptions, entity: _entity) { (granted, error) in
|
|
|
|
|
|
if granted {
|
|
@@ -135,13 +150,63 @@ public extension UMManager {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- UMessage.setBadgeClear(true)//设置是否允许SDK自动清空角标
|
|
|
- UMessage.openDebugMode(true)
|
|
|
- UMessage.setWebViewClassString("UMWebViewController")
|
|
|
- UMessage.addLaunch()
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 添加别名
|
|
|
+ func addAlias() {
|
|
|
+ UMessage.addAlias(UserModel.shared().getModel()?.mobile ?? "", type: "CHXQ_MOBILE", response: { (data, error) in })
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 重置别名
|
|
|
+ func setAlias() {
|
|
|
+ UMessage.setAlias(UserModel.shared().getModel()?.mobile ?? "", type: "CHXQ_MOBILE", response: { (data, error) in })
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 移除别名
|
|
|
+ func removeAlias() {
|
|
|
+ UMessage.removeAlias(UserModel.shared().getModel()?.mobile ?? "", type: "CHXQ_MOBILE", response: { (data, error) in })
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+@available(iOS 10.0, *)
|
|
|
+// MARK: - UNUserNotificationCenterDelegate
|
|
|
+extension UMManager:UNUserNotificationCenterDelegate {
|
|
|
+ public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
|
+ let userInfo = notification.request.content.userInfo
|
|
|
+
|
|
|
+ if (notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
|
|
|
+ UMessage.setAutoAlert(false)
|
|
|
+ //应用处于前台时的远程推送接受
|
|
|
+// let json = JSON(userInfo)
|
|
|
+// RouterManager.shared.UMPush(pushModel: PushModel(JSONString: json.description) ?? PushModel())
|
|
|
+ //必须加这句代码
|
|
|
+ UMessage.didReceiveRemoteNotification(userInfo)
|
|
|
+
|
|
|
+ }else {
|
|
|
+ //应用处于前台时的本地推送接受
|
|
|
+ }
|
|
|
+ completionHandler(UNNotificationPresentationOptions(rawValue: UNNotificationPresentationOptions.sound.rawValue|UNNotificationPresentationOptions.alert.rawValue|UNNotificationPresentationOptions.badge.rawValue))
|
|
|
+ }
|
|
|
+
|
|
|
+ public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
|
+ let userInfo = response.notification.request.content.userInfo
|
|
|
+ if (response.notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
|
|
|
+ UMessage.setAutoAlert(false)
|
|
|
+ //应用处于后台时的远程推送接受
|
|
|
+ let json = JSON(userInfo)
|
|
|
+ RouterManager.shared.UMPush(pushModel: PushModel(JSONString: json.description) ?? PushModel())
|
|
|
+
|
|
|
+ //必须加这句代码
|
|
|
+ UMessage.didReceiveRemoteNotification(userInfo)
|
|
|
+
|
|
|
+ }else {
|
|
|
+ //应用处于前台时的本地推送接受
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// MARK: 分享
|
|
|
public extension UMManager {
|
|
|
/// 分享设置
|
|
@@ -212,13 +277,13 @@ public extension UMManager {
|
|
|
UMSocialUIManager.showShareMenuViewInWindow(platformSelectionBlock: {[weak self] platformType, userInfo in
|
|
|
switch shareType {
|
|
|
case .text:
|
|
|
- self?.shareText(to: platformType, viewController: viewController,text: text)
|
|
|
+ self?.shareText(to: platformType, viewController: viewController,text: text,completion: nil)
|
|
|
break
|
|
|
case .image:
|
|
|
- self?.shareImage(to: platformType, viewController: viewController,thumbImage: thumbImage,shareImage: shareImage)
|
|
|
+ self?.shareImage(to: platformType, viewController: viewController,thumbImage: thumbImage,shareImage: shareImage,completion: nil)
|
|
|
break
|
|
|
case .webPage:
|
|
|
- self?.shareWebPage(to: platformType, viewController: viewController,title: title,descr: descr, thumbImage: thumbImage,webpageUrl: webpageUrl)
|
|
|
+ self?.shareWebPage(to: platformType, viewController: viewController,title: title,descr: descr, thumbImage: thumbImage,webpageUrl: webpageUrl, completion: nil)
|
|
|
break
|
|
|
}
|
|
|
})
|
|
@@ -230,24 +295,15 @@ public extension UMManager {
|
|
|
/// - platformType: 平台
|
|
|
/// - viewController: 控制器
|
|
|
/// - text: 分享文本
|
|
|
- func shareText(to platformType: UMSocialPlatformType,viewController:UIViewController,text:String) {
|
|
|
+ func shareText(to platformType: UMSocialPlatformType,viewController:UIViewController,text:String,completion: (() -> Void)?) {
|
|
|
//创建分享消息对象
|
|
|
let messageObject = UMSocialMessageObject()
|
|
|
//设置文本
|
|
|
messageObject.text = text
|
|
|
|
|
|
//调用分享接口
|
|
|
- UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: viewController) { data, error in
|
|
|
- if error != nil {
|
|
|
- if let anError = error {
|
|
|
- NXLLog("************Share fail with error \(anError)*********")
|
|
|
- }
|
|
|
- } else {
|
|
|
- if let aData = data {
|
|
|
- NXLLog("response data is \(aData)")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ isPlatformInstall(platformType: platformType, messageObject: messageObject, viewController: viewController, completion: completion)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// 分享图片
|
|
@@ -257,7 +313,7 @@ public extension UMManager {
|
|
|
/// - viewController: 控制器
|
|
|
/// - thumbImage: 缩略图
|
|
|
/// - shareImage: 分享图
|
|
|
- func shareImage(to platformType: UMSocialPlatformType,viewController:UIViewController,thumbImage:Any,shareImage:Any) {
|
|
|
+ func shareImage(to platformType: UMSocialPlatformType,viewController:UIViewController,thumbImage:Any,shareImage:Any,completion: (() -> Void)?) {
|
|
|
//创建分享消息对象
|
|
|
let messageObject = UMSocialMessageObject()
|
|
|
|
|
@@ -271,17 +327,9 @@ public extension UMManager {
|
|
|
messageObject.shareObject = shareObject
|
|
|
|
|
|
//调用分享接口
|
|
|
- UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: viewController) { data, error in
|
|
|
- if error != nil {
|
|
|
- if let anError = error {
|
|
|
- NXLLog("************Share fail with error \(anError)*********")
|
|
|
- }
|
|
|
- } else {
|
|
|
- if let aData = data {
|
|
|
- NXLLog("response data is \(aData)")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ isPlatformInstall(platformType: platformType, messageObject: messageObject, viewController: viewController, completion: completion)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// 分享网页
|
|
@@ -293,7 +341,7 @@ public extension UMManager {
|
|
|
/// - descr: 内容描述
|
|
|
/// - thumbImage: 缩略图
|
|
|
/// - webpageUrl: 链接地址
|
|
|
- func shareWebPage(to platformType: UMSocialPlatformType,viewController:UIViewController,title:String,descr:String,thumbImage:Any,webpageUrl:String) {
|
|
|
+ func shareWebPage(to platformType: UMSocialPlatformType,viewController:UIViewController,title:String,descr:String,thumbImage:Any,webpageUrl:String,completion: (() -> Void)?) {
|
|
|
//创建分享消息对象
|
|
|
let messageObject = UMSocialMessageObject()
|
|
|
|
|
@@ -304,17 +352,40 @@ public extension UMManager {
|
|
|
|
|
|
//分享消息对象设置分享内容对象
|
|
|
messageObject.shareObject = shareObject
|
|
|
-
|
|
|
+
|
|
|
+ isPlatformInstall(platformType: platformType, messageObject: messageObject, viewController: viewController, completion: completion)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func isPlatformInstall(platformType:UMSocialPlatformType,messageObject:UMSocialMessageObject,viewController:Any,completion: (() -> Void)?) {
|
|
|
+
|
|
|
+ if platformType == .sina {
|
|
|
+ //调用分享接口
|
|
|
+ share(platformType: platformType, messageObject: messageObject, viewController: viewController, completion: completion)
|
|
|
+ } else if platformType == .wechatSession || platformType == .wechatTimeLine {
|
|
|
+ if (UMSocialManager.default()?.isInstall(platformType))! {
|
|
|
+ //调用分享接口
|
|
|
+ share(platformType: platformType, messageObject: messageObject, viewController: viewController, completion: completion)
|
|
|
+ }else {
|
|
|
+ SwiftProgressHUD.shared().showText("微信未安装,请您先安装")
|
|
|
+ }
|
|
|
+ } else if platformType == .QQ {
|
|
|
+ if (UMSocialManager.default()?.isInstall(platformType))! {
|
|
|
+ share(platformType: platformType, messageObject: messageObject, viewController: viewController, completion: completion)
|
|
|
+ }else {
|
|
|
+ SwiftProgressHUD.shared().showText("QQ未安装,请您先安装")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private func share(platformType:UMSocialPlatformType,messageObject:UMSocialMessageObject,viewController:Any,completion: (() -> Void)?) {
|
|
|
//调用分享接口
|
|
|
UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: viewController) { data, error in
|
|
|
if error != nil {
|
|
|
- if let anError = error {
|
|
|
- NXLLog("************Share fail with error \(anError)*********")
|
|
|
- }
|
|
|
+ SwiftProgressHUD.shared().showText("分享失败")
|
|
|
} else {
|
|
|
- if let aData = data {
|
|
|
- NXLLog("response data is \(aData)")
|
|
|
- }
|
|
|
+ SwiftProgressHUD.shared().showText("分享成功")
|
|
|
+ completion?()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -332,83 +403,58 @@ extension UMManager {
|
|
|
}
|
|
|
let isInstall = UMSocialManager.default()?.isInstall(platformType)
|
|
|
if isInstall! { //验证
|
|
|
- UMSocialManager.default().getUserInfo(with: platformType, currentViewController: nil) { result, error in
|
|
|
-
|
|
|
- if error != nil {
|
|
|
- SwiftProgressHUD.shared().showText("授权失败,请重新登录")
|
|
|
- } else {
|
|
|
-
|
|
|
- let resp = result as? UMSocialUserInfoResponse
|
|
|
-
|
|
|
- let UserModel = UMLoginModel()
|
|
|
- // 第三方登录数据(为空表示平台未提供)
|
|
|
- // 授权数据
|
|
|
- if let anUid = resp?.uid {
|
|
|
- NXLLog(" uid: \(anUid)")
|
|
|
- UserModel.union_id = anUid
|
|
|
- }
|
|
|
- if let anOpenid = resp?.openid {
|
|
|
- NXLLog(" openid: \(anOpenid)")
|
|
|
- UserModel.open_id = anOpenid
|
|
|
- }
|
|
|
-
|
|
|
- // 用户数据
|
|
|
- if let aName = resp?.name {
|
|
|
- NXLLog(" name: \(aName)")
|
|
|
- UserModel.username = aName
|
|
|
- }
|
|
|
- if let anIconurl = resp?.iconurl {
|
|
|
- NXLLog(" iconurl: \(anIconurl)")
|
|
|
- UserModel.avatar = anIconurl
|
|
|
- }
|
|
|
- if let aGender = resp?.unionGender {
|
|
|
- NXLLog(" gender: \(aGender)")
|
|
|
- if aGender == "男" {
|
|
|
- UserModel.gender = 1
|
|
|
- }else if aGender == "女" {
|
|
|
- UserModel.gender = 2
|
|
|
- }
|
|
|
- }
|
|
|
- callBack(UserModel)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
+ getUserInfo(platformType: platformType, callBack: callBack)
|
|
|
+ }else {
|
|
|
if platformType == .wechatSession {
|
|
|
SwiftProgressHUD.shared().showText("微信未安装\n请您安装微信程序")
|
|
|
+ }else{
|
|
|
+ getUserInfo(platformType: platformType, callBack: callBack)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-@available(iOS 10.0, *)
|
|
|
-// MARK: - UNUserNotificationCenterDelegate
|
|
|
-extension UMManager:UNUserNotificationCenterDelegate {
|
|
|
- public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
|
- let userInfo = notification.request.content.userInfo
|
|
|
-
|
|
|
- if (notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
|
|
|
- UMessage.setAutoAlert(true)
|
|
|
- //应用处于前台时的远程推送接受
|
|
|
- //必须加这句代码
|
|
|
- UMessage.didReceiveRemoteNotification(userInfo)
|
|
|
-
|
|
|
- }else {
|
|
|
- //应用处于前台时的本地推送接受
|
|
|
- }
|
|
|
- completionHandler(UNNotificationPresentationOptions(rawValue: UNNotificationPresentationOptions.sound.rawValue|UNNotificationPresentationOptions.alert.rawValue|UNNotificationPresentationOptions.badge.rawValue))
|
|
|
- }
|
|
|
-
|
|
|
- public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
|
- let userInfo = response.notification.request.content.userInfo
|
|
|
- if (response.notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
|
|
|
- UMessage.setAutoAlert(true)
|
|
|
- //应用处于前台时的远程推送接受
|
|
|
- //必须加这句代码
|
|
|
- UMessage.didReceiveRemoteNotification(userInfo)
|
|
|
- }else {
|
|
|
- //应用处于前台时的本地推送接受
|
|
|
+func getUserInfo(platformType: UMSocialPlatformType,callBack: @escaping (UMLoginModel) -> (Void)) {
|
|
|
+ UMSocialManager.default().getUserInfo(with: platformType, currentViewController: nil) { result, error in
|
|
|
+
|
|
|
+ if error != nil {
|
|
|
+ SwiftProgressHUD.shared().showText("授权失败,请重新登录")
|
|
|
+ } else {
|
|
|
+
|
|
|
+ let resp = result as? UMSocialUserInfoResponse
|
|
|
+
|
|
|
+ let UserModel = UMLoginModel()
|
|
|
+ // 第三方登录数据(为空表示平台未提供)
|
|
|
+ // 授权数据
|
|
|
+ if let anUid = resp?.uid {
|
|
|
+ NXLLog(" uid: \(anUid)")
|
|
|
+ UserModel.union_id = anUid
|
|
|
+ }
|
|
|
+ if let anOpenid = resp?.openid {
|
|
|
+ NXLLog(" openid: \(anOpenid)")
|
|
|
+ UserModel.open_id = anOpenid
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户数据
|
|
|
+ if let aName = resp?.name {
|
|
|
+ NXLLog(" name: \(aName)")
|
|
|
+ UserModel.username = aName
|
|
|
+ }
|
|
|
+ if let anIconurl = resp?.iconurl {
|
|
|
+ NXLLog(" iconurl: \(anIconurl)")
|
|
|
+ UserModel.avatar = anIconurl
|
|
|
+ }
|
|
|
+ if let aGender = resp?.unionGender {
|
|
|
+ NXLLog(" gender: \(aGender)")
|
|
|
+ if aGender == "男" {
|
|
|
+ UserModel.gender = 1
|
|
|
+ }else if aGender == "女" {
|
|
|
+ UserModel.gender = 2
|
|
|
+ }
|
|
|
+ }
|
|
|
+ callBack(UserModel)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|