|
@@ -8,40 +8,39 @@
|
|
|
|
|
|
import UIKit
|
|
import UIKit
|
|
|
|
|
|
-enum ShareType {
|
|
|
|
|
|
+public enum ShareType {
|
|
case text
|
|
case text
|
|
case image
|
|
case image
|
|
case webPage
|
|
case webPage
|
|
}
|
|
}
|
|
|
|
|
|
-var _entity : UMessageRegisterEntity?
|
|
|
|
|
|
+public var _entity : UMessageRegisterEntity?
|
|
|
|
|
|
-class UMManager: NSObject {
|
|
|
|
|
|
+public class UMManager: NSObject {
|
|
private static let sharedInstance = UMManager()
|
|
private static let sharedInstance = UMManager()
|
|
|
|
+ private override init() {} // 私有化init方法
|
|
|
|
|
|
/// 单例
|
|
/// 单例
|
|
///
|
|
///
|
|
/// - Returns: UMShareManager对象
|
|
/// - Returns: UMShareManager对象
|
|
- class func shared() -> UMManager {
|
|
|
|
|
|
+ public class func shared() -> UMManager {
|
|
return sharedInstance
|
|
return sharedInstance
|
|
}
|
|
}
|
|
-
|
|
|
|
- private override init() {} // 私有化init方法
|
|
|
|
-
|
|
|
|
/// 友盟初始化
|
|
/// 友盟初始化
|
|
- func initUM(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
|
|
|
|
-
|
|
|
|
|
|
+ public func initUM(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
|
|
//公共
|
|
//公共
|
|
common()
|
|
common()
|
|
//推送
|
|
//推送
|
|
push(launchOptions: launchOptions)
|
|
push(launchOptions: launchOptions)
|
|
//分享
|
|
//分享
|
|
share()
|
|
share()
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
|
|
+// MARK: 公共
|
|
|
|
+public extension UMManager {
|
|
///公共
|
|
///公共
|
|
- func common() -> Void {
|
|
|
|
|
|
+ public func common() -> Void {
|
|
|
|
|
|
//将自动采集页面信息
|
|
//将自动采集页面信息
|
|
// MobClick.setAutoPageEnabled(true)
|
|
// MobClick.setAutoPageEnabled(true)
|
|
@@ -66,9 +65,13 @@ class UMManager: NSObject {
|
|
NXLLog("服务器端还没有返回deviceID");
|
|
NXLLog("服务器端还没有返回deviceID");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// MARK: 推送
|
|
|
|
+public extension UMManager {
|
|
|
|
|
|
///推送
|
|
///推送
|
|
- func push(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
|
|
|
|
|
|
+ public func push(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
|
|
|
|
|
|
_entity = UMessageRegisterEntity.init()
|
|
_entity = UMessageRegisterEntity.init()
|
|
//type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
|
|
//type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
|
|
@@ -120,8 +123,12 @@ class UMManager: NSObject {
|
|
}
|
|
}
|
|
UMessage.setBadgeClear(true)//设置是否允许SDK自动清空角标
|
|
UMessage.setBadgeClear(true)//设置是否允许SDK自动清空角标
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// MARK: 分享
|
|
|
|
+public extension UMManager {
|
|
/// 分享设置
|
|
/// 分享设置
|
|
- func share() -> Void {
|
|
|
|
|
|
+ public func share() -> Void {
|
|
/*
|
|
/*
|
|
设置微信的appKey和appSecret
|
|
设置微信的appKey和appSecret
|
|
[微信平台从U-Share 4/5升级说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_1
|
|
[微信平台从U-Share 4/5升级说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_1
|
|
@@ -156,7 +163,7 @@ class UMManager: NSObject {
|
|
/// - title: 标题
|
|
/// - title: 标题
|
|
/// - descr: 内容描述
|
|
/// - descr: 内容描述
|
|
/// - webpageUrl: 链接地址
|
|
/// - webpageUrl: 链接地址
|
|
- func UMSocialUI(shareType:ShareType, viewController:UIViewController,text:String,thumbImage:Any,shareImage:Any,title:String,descr:String,webpageUrl:String) -> Void {
|
|
|
|
|
|
+ public func UMSocialUI(shareType:ShareType, viewController:UIViewController,text:String,thumbImage:Any,shareImage:Any,title:String,descr:String,webpageUrl:String) -> Void {
|
|
|
|
|
|
UMSocialUIManager.showShareMenuViewInWindow(platformSelectionBlock: {[weak self] platformType, userInfo in
|
|
UMSocialUIManager.showShareMenuViewInWindow(platformSelectionBlock: {[weak self] platformType, userInfo in
|
|
switch shareType {
|
|
switch shareType {
|
|
@@ -179,7 +186,7 @@ class UMManager: NSObject {
|
|
/// - platformType: 平台
|
|
/// - platformType: 平台
|
|
/// - viewController: 控制器
|
|
/// - viewController: 控制器
|
|
/// - text: 分享文本
|
|
/// - text: 分享文本
|
|
- func shareText(to platformType: UMSocialPlatformType,viewController:UIViewController,text:String) {
|
|
|
|
|
|
+ public func shareText(to platformType: UMSocialPlatformType,viewController:UIViewController,text:String) {
|
|
//创建分享消息对象
|
|
//创建分享消息对象
|
|
let messageObject = UMSocialMessageObject()
|
|
let messageObject = UMSocialMessageObject()
|
|
//设置文本
|
|
//设置文本
|
|
@@ -206,7 +213,7 @@ class UMManager: NSObject {
|
|
/// - viewController: 控制器
|
|
/// - viewController: 控制器
|
|
/// - thumbImage: 缩略图
|
|
/// - thumbImage: 缩略图
|
|
/// - shareImage: 分享图
|
|
/// - shareImage: 分享图
|
|
- func shareImage(to platformType: UMSocialPlatformType,viewController:UIViewController,thumbImage:Any,shareImage:Any) {
|
|
|
|
|
|
+ public func shareImage(to platformType: UMSocialPlatformType,viewController:UIViewController,thumbImage:Any,shareImage:Any) {
|
|
//创建分享消息对象
|
|
//创建分享消息对象
|
|
let messageObject = UMSocialMessageObject()
|
|
let messageObject = UMSocialMessageObject()
|
|
|
|
|
|
@@ -242,7 +249,7 @@ class UMManager: NSObject {
|
|
/// - descr: 内容描述
|
|
/// - descr: 内容描述
|
|
/// - thumbImage: 缩略图
|
|
/// - thumbImage: 缩略图
|
|
/// - webpageUrl: 链接地址
|
|
/// - webpageUrl: 链接地址
|
|
- func shareWebPage(to platformType: UMSocialPlatformType,viewController:UIViewController,title:String,descr:String,thumbImage:Any,webpageUrl:String) {
|
|
|
|
|
|
+ public func shareWebPage(to platformType: UMSocialPlatformType,viewController:UIViewController,title:String,descr:String,thumbImage:Any,webpageUrl:String) {
|
|
//创建分享消息对象
|
|
//创建分享消息对象
|
|
let messageObject = UMSocialMessageObject()
|
|
let messageObject = UMSocialMessageObject()
|
|
|
|
|
|
@@ -267,11 +274,14 @@ class UMManager: NSObject {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
|
|
+// MARK: 第三方登录
|
|
|
|
+public extension UMManager {
|
|
/// 第三方登录
|
|
/// 第三方登录
|
|
///
|
|
///
|
|
/// - Parameter platformType: 平台
|
|
/// - Parameter platformType: 平台
|
|
- func loginGetUserInfo(platformType: UMSocialPlatformType) {
|
|
|
|
|
|
+ public func loginGetUserInfo(platformType: UMSocialPlatformType) {
|
|
UMSocialManager.default().getUserInfo(with: platformType, currentViewController: nil) { result, error in
|
|
UMSocialManager.default().getUserInfo(with: platformType, currentViewController: nil) { result, error in
|
|
|
|
|
|
if error != nil {
|
|
if error != nil {
|
|
@@ -317,11 +327,11 @@ class UMManager: NSObject {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-@available(iOS 10.0, *)
|
|
|
|
|
|
|
|
|
|
+@available(iOS 10.0, *)
|
|
// MARK: - UNUserNotificationCenterDelegate
|
|
// MARK: - UNUserNotificationCenterDelegate
|
|
extension UMManager:UNUserNotificationCenterDelegate {
|
|
extension UMManager:UNUserNotificationCenterDelegate {
|
|
- func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
|
|
|
|
+ private func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
let userInfo = notification.request.content.userInfo
|
|
let userInfo = notification.request.content.userInfo
|
|
|
|
|
|
if (notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
|
|
if (notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
|
|
@@ -336,7 +346,7 @@ extension UMManager:UNUserNotificationCenterDelegate {
|
|
completionHandler(UNNotificationPresentationOptions(rawValue: UNNotificationPresentationOptions.sound.rawValue|UNNotificationPresentationOptions.alert.rawValue|UNNotificationPresentationOptions.badge.rawValue))
|
|
completionHandler(UNNotificationPresentationOptions(rawValue: UNNotificationPresentationOptions.sound.rawValue|UNNotificationPresentationOptions.alert.rawValue|UNNotificationPresentationOptions.badge.rawValue))
|
|
}
|
|
}
|
|
|
|
|
|
- func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
|
|
|
|
+ private func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
let userInfo = response.notification.request.content.userInfo
|
|
let userInfo = response.notification.request.content.userInfo
|
|
if (response.notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
|
|
if (response.notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
|
|
UMessage.setAutoAlert(true)
|
|
UMessage.setAutoAlert(true)
|
|
@@ -346,8 +356,5 @@ extension UMManager:UNUserNotificationCenterDelegate {
|
|
}else {
|
|
}else {
|
|
//应用处于前台时的本地推送接受
|
|
//应用处于前台时的本地推送接受
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|