Skip to content

Commit

Permalink
Merge pull request #4 from nuomi1/feature/WeiboHandler
Browse files Browse the repository at this point in the history
feat: WeiboHandler
  • Loading branch information
nuomi1 authored Jan 24, 2021
2 parents 821b11f + 73f0783 commit 1593e8d
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 43 deletions.
63 changes: 46 additions & 17 deletions Example/NBus/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

clearStorage()

// observeQQ()
// observeSDK()

AppState.shared.setup()

Expand Down Expand Up @@ -67,48 +67,66 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

extension AppDelegate {

// swiftlint:disable function_body_length

private func pasteboardItems() -> Observable<[[String]]> {
NotificationCenter.default.rx
.notification(UIPasteboard.changedNotification)
.map { _ -> [[String]] in
UIPasteboard.general.items.map { item -> [String] in
let items = UIPasteboard.general.items

return items.enumerated().map { (index, item) -> [String] in
item.map { key, value -> String in
let identity: String
let index = "(\(index + 1)/\(items.count))"
let content: String

switch value {
case let data as Data:
if
let string = String(
data: data,
encoding: .utf8
) {
identity = "[Data-String]"
content = string
} else if
let object = NSKeyedUnarchiver.unarchiveObject(
with: data
) {
return "[Data-Keyed] \(key), \(object)"
identity = "[Data-Keyed]"
content = "\(object)"
} else if
let plist = try? PropertyListSerialization.propertyList(
from: data,
options: [],
format: nil
) {
return "[Data-Plist] \(key), \(plist)"
} else if
let string = String(
data: data,
encoding: .utf8
) {
return "[Data-String] \(key), \(string)"
identity = "[Data-Plist]"
content = "\(plist)"
} else {
assertionFailure()
return "\(key), \(value)"
identity = "[Data-Unknown]"
content = "\(value)"
}
case let string as String:
return "[String] \(key), \(string)"
identity = "[String]"
content = "\(string)"
default:
assertionFailure()
return "\(key), \(value)"
identity = "[Unknown]"
content = "\(value)"
}

return "\(identity)\(index), \(key), \(content)"
}
}
}
.distinctUntilChanged()
}

// swiftlint:enable function_body_length

private func canOpenURL() -> Observable<URL> {
UIApplication.shared.rx
.methodInvoked(#selector(UIApplication.canOpenURL(_:)))
Expand All @@ -118,17 +136,25 @@ extension AppDelegate {
}

private func openURL() -> Observable<URL> {
UIApplication.shared.rx
let oldURL = UIApplication.shared.rx
.methodInvoked(#selector(UIApplication.openURL(_:)))
.compactMap { args in
args[0] as? URL
}

let newURL = UIApplication.shared.rx
.methodInvoked(#selector(UIApplication.open(_:options:completionHandler:)))
.compactMap { args in
args[0] as? URL
}

return Observable.merge([oldURL, newURL])
}
}

extension AppDelegate {

private func observeSDK() {
private func observeSystem() {
pasteboardItems()
.bind(onNext: { items in
logger.debug("\(items)")
Expand Down Expand Up @@ -195,10 +221,13 @@ extension AppDelegate {

extension AppDelegate {

private func observeQQ() {
private func observeSDK() {
// SwiftTrace.traceClasses(matchingPattern: "^QQ")
// SwiftTrace.traceClasses(matchingPattern: "^Tencent")

observeSDK()
// SwiftTrace.traceClasses(matchingPattern: "^WB")
// SwiftTrace.traceClasses(matchingPattern: "^Weibo")

observeSystem()
}
}
2 changes: 1 addition & 1 deletion Example/NBus/Config.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ WECHAT_APPID = wx$(WECHAT_ID)
WECHAT_MINIPROGRAMID = gh_$(WECHAT_MID)
WECHAT_UNIVERSALLINK = https:$(SIMPLE_SLASH)/$(DOMAIN)/wechat/$(WECHAT_ID)/
WEIBO_APPID = wb$(WEIBO_ID)
WEIBO_REDIRECTLINK = https:$(SIMPLE_SLASH)/$(DOMAIN)/weibo/$(WEIBO_ID)/
WEIBO_REDIRECTLINK = https:$(SIMPLE_SLASH)/api.weibo.com/oauth2/default.html
WEIBO_UNIVERSALLINK = https:$(SIMPLE_SLASH)/$(DOMAIN)/weibo/$(WEIBO_ID)/
7 changes: 7 additions & 0 deletions Example/NBus/Model/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,17 @@ extension AppState {
logger.debug("\(message)", file: file, function: function, line: line)
}

let weiboHandler = WeiboHandler(
appID: AppState.getAppID(for: Platforms.weibo)!,
universalLink: AppState.getUniversalLink(for: Platforms.weibo)!,
redirectLink: AppState.getRedirectLink(for: Platforms.weibo)!
)

let weiboItem = AppState.PlatformItem(
platform: Platforms.weibo,
category: .sdk,
handlers: [
.bus: weiboHandler,
.sdk: weiboSDKHandler,
],
viewController: { PlatformViewController() }
Expand Down
7 changes: 6 additions & 1 deletion Example/NBus/Model/MediaSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ enum MediaSource {
let title = "iPhone"
let description = "Apple"

let dataAsset = NSDataAsset(name: "giphy-J1ZajKJKzD0PK")!
let data = dataAsset.data
let thumbnail = UIImage(data: data)?.jpegData(compressionQuality: 0.2)

return Messages.webPage(
link: url,
title: title,
description: description
description: description,
thumbnail: thumbnail
)
}()

Expand Down
27 changes: 15 additions & 12 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
PODS:
- NBus/BusHandlers (0.7.0):
- NBus/BusHandlers (0.8.1):
- NBus/QQHandler
- NBus/SystemHandler
- NBus/Core (0.7.0)
- NBus/QQHandler (0.7.0):
- NBus/WeiboHandler
- NBus/Core (0.8.1)
- NBus/QQHandler (0.8.1):
- NBus/Core
- NBus/QQSDK (0.7.0)
- NBus/QQSDKHandler (0.7.0):
- NBus/QQSDK (0.8.1)
- NBus/QQSDKHandler (0.8.1):
- NBus/Core
- NBus/QQSDK
- NBus/SDKHandlers (0.7.0):
- NBus/SDKHandlers (0.8.1):
- NBus/QQSDKHandler
- NBus/SystemHandler
- NBus/WechatSDKHandler
- NBus/WeiboSDKHandler
- NBus/SystemHandler (0.7.0):
- NBus/SystemHandler (0.8.1):
- NBus/Core
- NBus/WechatSDK (0.7.0)
- NBus/WechatSDKHandler (0.7.0):
- NBus/WechatSDK (0.8.1)
- NBus/WechatSDKHandler (0.8.1):
- NBus/Core
- NBus/WechatSDK
- NBus/WeiboSDK (0.7.0)
- NBus/WeiboSDKHandler (0.7.0):
- NBus/WeiboHandler (0.8.1):
- NBus/Core
- NBus/WeiboSDK (0.8.1)
- NBus/WeiboSDKHandler (0.8.1):
- NBus/Core
- NBus/WeiboSDK
- PinLayout (1.9.3)
Expand Down Expand Up @@ -56,7 +59,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
NBus: 909effc8a33bd2e5e3549406dc8b718f028f1776
NBus: 97c14cb69f0ec19bd0752f5e25a3518849b81f8c
PinLayout: 4d8733121f8687edcc8f00c19bf1379d12808767
RxCocoa: 3f79328fafa3645b34600f37c31e64c73ae3a80e
RxRelay: 8d593be109c06ea850df027351beba614b012ffb
Expand Down
7 changes: 7 additions & 0 deletions NBus.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Pod::Spec.new do |s|

s.subspec "BusHandlers" do |ss|
ss.dependency "NBus/QQHandler"
ss.dependency "NBus/WeiboHandler"
ss.dependency "NBus/SystemHandler"
end

Expand Down Expand Up @@ -57,6 +58,12 @@ Pod::Spec.new do |s|
ss.source_files = ["NBus/Classes/Handler/WeiboSDKHandler.swift"]
end

s.subspec "WeiboHandler" do |ss|
ss.dependency "NBus/Core"

ss.source_files = ["NBus/Classes/Handler/WeiboHandler.swift"]
end

s.subspec "SystemHandler" do |ss|
ss.dependency "NBus/Core"

Expand Down
5 changes: 5 additions & 0 deletions NBus/Classes/Core/Bus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,10 @@ extension Bus {

static let openID = Bus.OauthInfoKey(rawValue: "com.nuomi1.bus.qq.openID")
}

enum Weibo {

public static let accessToken = Bus.OauthInfoKey(rawValue: "com.nuomi1.bus.weibo.accessToken")
}
}
}
Loading

0 comments on commit 1593e8d

Please sign in to comment.