mirror of
https://github.com/wahyd4/libr-ios.git
synced 2026-08-09 05:06:46 +10:00
share plugin
This commit is contained in:
@@ -62,6 +62,7 @@
|
||||
45A50FC01BC96608009897FF /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45A50FBF1BC96608009897FF /* Profile.swift */; };
|
||||
45AD0E2E1B857EA600283FCC /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45AD0E2D1B857EA600283FCC /* WebViewController.swift */; };
|
||||
45B11CD81B6FD12A008D6049 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 45B11CD71B6FD12A008D6049 /* Images.xcassets */; };
|
||||
45C011E41C01FC9900A9BACF /* ShareService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45C011E31C01FC9900A9BACF /* ShareService.swift */; };
|
||||
45C24EFB1BAD899D00BACB81 /* DashViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45C24EFA1BAD899D00BACB81 /* DashViewController.swift */; };
|
||||
45C24EFE1BADA48E00BACB81 /* UIColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45C24EFD1BADA48E00BACB81 /* UIColorExtension.swift */; };
|
||||
45CE21A31BC2797300642186 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 45CE21A21BC2797300642186 /* CoreTelephony.framework */; };
|
||||
@@ -221,6 +222,7 @@
|
||||
45A50FBF1BC96608009897FF /* Profile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Profile.swift; sourceTree = "<group>"; };
|
||||
45AD0E2D1B857EA600283FCC /* WebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = "<group>"; };
|
||||
45B11CD71B6FD12A008D6049 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
|
||||
45C011E31C01FC9900A9BACF /* ShareService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShareService.swift; sourceTree = "<group>"; };
|
||||
45C24EFA1BAD899D00BACB81 /* DashViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashViewController.swift; sourceTree = "<group>"; };
|
||||
45C24EFD1BADA48E00BACB81 /* UIColorExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIColorExtension.swift; sourceTree = "<group>"; };
|
||||
45CE21A21BC2797300642186 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; };
|
||||
@@ -526,6 +528,7 @@
|
||||
453B01521BAADC2400E285A3 /* JsonPaser.swift */,
|
||||
45CE21A41BC35D7800642186 /* DateUtil.swift */,
|
||||
4599CCE01BFCAC7E00F263BC /* PostsStore.swift */,
|
||||
45C011E31C01FC9900A9BACF /* ShareService.swift */,
|
||||
);
|
||||
name = services;
|
||||
sourceTree = "<group>";
|
||||
@@ -884,6 +887,7 @@
|
||||
45A50FC01BC96608009897FF /* Profile.swift in Sources */,
|
||||
452DC1191B6287E600847691 /* AppDelegate.swift in Sources */,
|
||||
45681F341B7F7C8A00D1E096 /* User.swift in Sources */,
|
||||
45C011E41C01FC9900A9BACF /* ShareService.swift in Sources */,
|
||||
457BF0E11B9C905B00A491D6 /* ExploreCollectionReusableView.swift in Sources */,
|
||||
45681F301B7F79AF00D1E096 /* Shareable.swift in Sources */,
|
||||
4544DAD61BCD4358002B6666 /* SettingTableViewController.swift in Sources */,
|
||||
|
||||
@@ -40,6 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
func applicationWillEnterForeground(application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
ShareService().fetchAndSaveNewMemos()
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(application: UIApplication) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9052" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9040"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
|
||||
@@ -444,7 +444,7 @@
|
||||
<pageViewController autoresizesArchivedViewToFullSize="NO" transitionStyle="pageCurl" navigationOrientation="horizontal" spineLocation="min" id="w7v-wp-S5s" customClass="ContainerViewController" customModule="librx" customModuleProvider="target" sceneMemberID="viewController"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="TJH-1V-qao" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-6409" y="5299.5"/>
|
||||
<point key="canvasLocation" x="-6249" y="4655.5"/>
|
||||
</scene>
|
||||
<!--GraphsUI View Controller-->
|
||||
<scene sceneID="Rkh-y5-tfm">
|
||||
@@ -835,7 +835,7 @@
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="wQd-t8-Eyc" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-7117" y="5017"/>
|
||||
<point key="canvasLocation" x="-7177" y="5005"/>
|
||||
</scene>
|
||||
<!--探索发现-->
|
||||
<scene sceneID="Krh-MH-97G">
|
||||
|
||||
@@ -103,6 +103,13 @@
|
||||
"role" : "appLauncher",
|
||||
"subtype" : "38mm"
|
||||
},
|
||||
{
|
||||
"size" : "44x44",
|
||||
"idiom" : "watch",
|
||||
"scale" : "2x",
|
||||
"role" : "longLook",
|
||||
"subtype" : "42mm"
|
||||
},
|
||||
{
|
||||
"size" : "86x86",
|
||||
"idiom" : "watch",
|
||||
|
||||
@@ -476,4 +476,6 @@ struct LibrxService {
|
||||
Alamofire.request(.POST, urlString, headers: headers)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -62,4 +62,6 @@ struct LocalStore {
|
||||
self.deleteAccessUserId()
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -20,13 +20,14 @@ class ProfileViewController: UIViewController{
|
||||
@IBOutlet weak var settingButton: UIButton!
|
||||
@IBOutlet weak var backButton: UIButton!
|
||||
|
||||
|
||||
private var containerViewController: ContainerViewController!
|
||||
private var screenSize: CGRect!
|
||||
private var screenWidth: CGFloat!
|
||||
private var screenHeight: CGFloat!
|
||||
private var isFollowed: Bool = true
|
||||
|
||||
private var profile: Profile?
|
||||
|
||||
// 其他用户个人中心
|
||||
var forceHiddenBackButton: Bool = false
|
||||
var isMe:Bool = true
|
||||
@@ -92,6 +93,7 @@ class ProfileViewController: UIViewController{
|
||||
|
||||
if let selfView = self {
|
||||
if let thatProfile = profile {
|
||||
selfView.profile = thatProfile
|
||||
let avatar = NSURL(string: thatProfile.avatar)
|
||||
selfView.avatarImageView.sd_setImageWithURL(avatar, placeholderImage: UIImage(named: "default"))
|
||||
selfView.nameLabel.text = thatProfile.name
|
||||
@@ -127,6 +129,7 @@ class ProfileViewController: UIViewController{
|
||||
|
||||
if let selfView = self {
|
||||
if let _ = profile {
|
||||
self?.profile = profile
|
||||
let avatar = NSURL(string: profile!.avatar)
|
||||
selfView.avatarImageView.sd_setImageWithURL(avatar, placeholderImage: UIImage(named: "default"))
|
||||
selfView.nameLabel.text = profile!.name
|
||||
@@ -157,11 +160,13 @@ class ProfileViewController: UIViewController{
|
||||
if self.isFollowed {
|
||||
self.isFollowed = false
|
||||
self.followButton.setTitle("关注", forState: .Normal)
|
||||
self.follosNumLabel.text = String(self.profile!.followsCount-1)
|
||||
LibrxService.unFollow(userId!)
|
||||
return
|
||||
} else {
|
||||
self.isFollowed = true
|
||||
self.followButton.setTitle("已关注", forState: .Normal)
|
||||
self.follosNumLabel.text = String(self.profile!.followsCount+1)
|
||||
LibrxService.follow(userId!)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// ShareService.swift
|
||||
// librx
|
||||
//
|
||||
// Created by Yunlong Zheng on 11/22/15.
|
||||
// Copyright © 2015 librx. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class ShareService {
|
||||
|
||||
func fetchAndSaveNewMemos(){
|
||||
|
||||
let sharedDefaults = NSUserDefaults(suiteName: "group.librme")
|
||||
print("load share content from share storage")
|
||||
let dict = sharedDefaults?.objectForKey("ShareContents") as? [AnyObject]
|
||||
if let contents = dict {
|
||||
|
||||
for content in contents {
|
||||
print("\(content)")
|
||||
let post = Post(url: String(content))
|
||||
LibrxService.createPost(post) { (json) -> () in
|
||||
print(json)
|
||||
};
|
||||
}
|
||||
|
||||
sharedDefaults?.removeObjectForKey("ShareContents")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,12 +12,19 @@ import MobileCoreServices
|
||||
|
||||
class ShareViewController: SLComposeServiceViewController {
|
||||
|
||||
private var shareUrlString: String?
|
||||
|
||||
lazy var sharedDefaults: NSUserDefaults? = {
|
||||
return NSUserDefaults(suiteName: "group.librme")
|
||||
}()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
for item: AnyObject in self.extensionContext!.inputItems {
|
||||
let inputItem = item as! NSExtensionItem
|
||||
for provider: AnyObject in inputItem.attachments! {
|
||||
|
||||
let itemProvider = provider as! NSItemProvider
|
||||
if itemProvider.hasItemConformingToTypeIdentifier(kUTTypePropertyList as String) {
|
||||
// You _HAVE_ to call loadItemForTypeIdentifier in order to get the JS injected
|
||||
@@ -31,29 +38,30 @@ class ShareViewController: SLComposeServiceViewController {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func itemLoadCompletedWithPreprocessingResults(javaScriptPreprocessingResults: NSDictionary) {
|
||||
if let text = javaScriptPreprocessingResults["baseURI"] as? String {
|
||||
let userDefaults = NSUserDefaults.init(suiteName: "group.librme")
|
||||
print(">>>>>\(userDefaults!.integerForKey("accessTokenKey"))\n")
|
||||
print("share url\(text)\n")
|
||||
self.doneWithResults(["message": "Successfully added to the note app"])
|
||||
if let urlString = javaScriptPreprocessingResults["baseURI"] as? String {
|
||||
|
||||
self.shareUrlString = urlString
|
||||
//print("share url:\(urlString)\n")
|
||||
//self.doneWithResults(["message": "Successfully added to the note app"])
|
||||
}
|
||||
}
|
||||
|
||||
func doneWithResults(resultsForJavaScriptFinalizeArg: NSDictionary?) {
|
||||
if let resultsForJavaScriptFinalize = resultsForJavaScriptFinalizeArg {
|
||||
let identifierType = NSString(format: kUTTypePropertyList, NSUTF8StringEncoding)
|
||||
|
||||
let identifierType = NSString(format: kUTTypePropertyList, NSUTF8StringEncoding)
|
||||
let resultsDictionary = [NSExtensionJavaScriptFinalizeArgumentKey: resultsForJavaScriptFinalize]
|
||||
let resultsProvider = NSItemProvider(item: resultsDictionary, typeIdentifier: identifierType as String)
|
||||
let resultsItem = NSExtensionItem()
|
||||
resultsItem.attachments = [resultsProvider]
|
||||
|
||||
self.extensionContext!.completeRequestReturningItems([resultsItem], completionHandler: nil)
|
||||
|
||||
} else {
|
||||
// 就算我们没有任何要返回的信息,也要执行这段代码,用于告知我们的Action扩展已经完成了逻辑处理。
|
||||
self.extensionContext!.completeRequestReturningItems(nil, completionHandler: nil)
|
||||
@@ -70,8 +78,18 @@ class ShareViewController: SLComposeServiceViewController {
|
||||
// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
|
||||
|
||||
// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
|
||||
print("didSelectPost: \(contentText)")
|
||||
print("didSelectPost: \(self.shareUrlString)")
|
||||
|
||||
var results = sharedDefaults?.objectForKey("ShareContents") as? [AnyObject]
|
||||
if results != nil {
|
||||
results!.append(self.shareUrlString!)
|
||||
sharedDefaults?.setObject(results, forKey: "ShareContents")
|
||||
}else{
|
||||
let contents = [self.shareUrlString!]
|
||||
sharedDefaults?.setObject(contents, forKey: "ShareContents")
|
||||
}
|
||||
|
||||
sharedDefaults!.synchronize()
|
||||
self.extensionContext!.completeRequestReturningItems([], completionHandler: nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user