Skip to content

Commit

Permalink
present view controller with original function
Browse files Browse the repository at this point in the history
  • Loading branch information
huylv-teko committed Oct 21, 2020
1 parent 0478932 commit 741941c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 15 deletions.
3 changes: 3 additions & 0 deletions BSImagePicker.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
55300E08222ED2530086E439 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 55300E06222ED2530086E439 /* LaunchScreen.storyboard */; };
55F67B7C222F106F00805134 /* BSImagePicker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55F67B66222ED56300805134 /* BSImagePicker.framework */; };
55F67B7D222F106F00805134 /* BSImagePicker.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 55F67B66222ED56300805134 /* BSImagePicker.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
A4A434623B005765DB145BCA /* libPods-Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 438C0948FCFA747524306BEF /* libPods-Example.a */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -42,6 +43,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
438C0948FCFA747524306BEF /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
551D6962230FCDDC006B1481 /* UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
551D6964230FCDDC006B1481 /* UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITests.swift; sourceTree = "<group>"; };
551D6966230FCDDC006B1481 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -53,6 +55,8 @@
55300E07222ED2530086E439 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
55300E09222ED2530086E439 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
55F67B66222ED56300805134 /* BSImagePicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BSImagePicker.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5B6E1AEA5DFC7D6A4B2D8F0C /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = "<group>"; };
B6F27CE7255ABDEA75EB13D2 /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -68,6 +72,7 @@
buildActionMask = 2147483647;
files = (
55F67B7C222F106F00805134 /* BSImagePicker.framework in Frameworks */,
A4A434623B005765DB145BCA /* libPods-Example.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -90,6 +95,7 @@
551D6963230FCDDC006B1481 /* UITests */,
55300DFB222ED2520086E439 /* Products */,
55F67B65222ED56300805134 /* Frameworks */,
B9FB7690A29687B624C8F391 /* Pods */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -119,10 +125,21 @@
isa = PBXGroup;
children = (
55F67B66222ED56300805134 /* BSImagePicker.framework */,
438C0948FCFA747524306BEF /* libPods-Example.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
B9FB7690A29687B624C8F391 /* Pods */ = {
isa = PBXGroup;
children = (
5B6E1AEA5DFC7D6A4B2D8F0C /* Pods-Example.debug.xcconfig */,
B6F27CE7255ABDEA75EB13D2 /* Pods-Example.release.xcconfig */,
);
name = Pods;
path = Example/Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -148,6 +165,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 55300E17222ED2530086E439 /* Build configuration list for PBXNativeTarget "Example" */;
buildPhases = (
01CBEF346D56BCF09FAE864C /* [CP] Check Pods Manifest.lock */,
55300DF6222ED2520086E439 /* Sources */,
55300DF7222ED2520086E439 /* Frameworks */,
55300DF8222ED2520086E439 /* Resources */,
Expand Down Expand Up @@ -221,6 +239,31 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
01CBEF346D56BCF09FAE864C /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Example-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
551D695E230FCDDC006B1481 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -429,6 +472,7 @@
};
55300E18222ED2530086E439 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5B6E1AEA5DFC7D6A4B2D8F0C /* Pods-Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
Expand All @@ -448,6 +492,7 @@
};
55300E19222ED2530086E439 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = B6F27CE7255ABDEA75EB13D2 /* Pods-Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
Expand Down
18 changes: 3 additions & 15 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,8 @@ class ViewController: UIViewController {
.video(max: 1)
]

let start = Date()
imagePicker.imagePickerDelegate = self
self.presentImagePicker(imagePicker, select: { (asset) in
print("Selected: \(asset)")
}, deselect: { (asset) in
print("Deselected: \(asset)")
}, cancel: { (assets) in
print("Canceled with selections: \(assets)")
}, finish: { (assets) in
print("Finished with selections: \(assets)")
}, completion: {
let finish = Date()
print(finish.timeIntervalSince(start))
})
self.present(imagePicker, animated: true)

}
}
Expand All @@ -149,11 +137,11 @@ extension ViewController: ImagePickerControllerDelegate {
}

func imagePicker(_ imagePicker: ImagePickerController, didFinishWithAssets assets: [PHAsset]) {
print("Canceled with selections: \(assets)")
print("Finished with selections: \(assets)")
}

func imagePicker(_ imagePicker: ImagePickerController, didCancelWithAssets assets: [PHAsset]) {
print("Finished with selections: \(assets)")
print("Canceled with selections: \(assets)")
}

func imagePicker(_ imagePicker: ImagePickerController, didReachSelectionLimit count: Int) {
Expand Down
29 changes: 29 additions & 0 deletions Sources/Controller/ImagePickerController+Closure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import Photos
imagePicker.onCancel = cancel
imagePicker.onFinish = finish

// And since we are using the blocks api. Set ourselfs as delegate
imagePicker.imagePickerDelegate = imagePicker

// Present
self.present(imagePicker, animated: animated, completion: completion)
}
Expand All @@ -67,3 +70,29 @@ extension ImagePickerController {
return PHPhotoLibrary.authorizationStatus()
}
}

/// ImagePickerControllerDelegate closure wrapper
extension ImagePickerController: ImagePickerControllerDelegate {
public func imagePicker(_ imagePicker: ImagePickerController, didReachSelectionLimitForType type: PHAssetMediaType) {
}

public func imagePicker(_ imagePicker: ImagePickerController, didSelectAsset asset: PHAsset) {
onSelection?(asset)
}

public func imagePicker(_ imagePicker: ImagePickerController, didDeselectAsset asset: PHAsset) {
onDeselection?(asset)
}

public func imagePicker(_ imagePicker: ImagePickerController, didFinishWithAssets assets: [PHAsset]) {
onFinish?(assets)
}

public func imagePicker(_ imagePicker: ImagePickerController, didCancelWithAssets assets: [PHAsset]) {
onCancel?(assets)
}

public func imagePicker(_ imagePicker: ImagePickerController, didReachSelectionLimit count: Int) {

}
}

0 comments on commit 741941c

Please sign in to comment.