Skip to content

sweetmans/InstagramPhotos

Repository files navigation

Version License Platform Reviewed by Hound

To be contributed with me

Twitter PM me Twitter

The latest MAJOR release: 2.0.0 RELEASENOTE.md

  • Rename to InstagramPhotos
  • Migrated to Xcode 12
  • New UI design same with instagram
  • Adding localization support
  • Supporting new iOS 14 photos limited access system

The latest release 2.0.3 Latest RELEASENOTE.md

TO DO

If you like this framework. Please give me a star ⭐️

Contributor

Welcome to be one of us 🧑🏻‍💻🧑‍💻🧑🏼‍💻🧑🏽‍💻🧑🏾‍💻🧑🏿‍💻

Features

  • New UI design same with instagram
  • Adding localization support
  • Supporting new iOS 14 photos limited access system
  • So easy to use.
  • Support Swift 5.0 and above
  • Performances!
  • Use GCD and ARC
  • Supported iOS 11.0 and above

Requirements

  • iOS 12.0 or later
  • Xcode 12.0 or later
  • swift 5.0 or later

Getting Started

Installation

SMInstagramPhotoPicker is available through CocoaPods. To install it, simply add the following line to your Podfile:

Cocoapods

pod 'InstagramPhotos'

Swift Package Manager (Bundle issue could not use swift package right now)

dependencies: [
    .package(url: "https://github.com/sweetmans/InstagramPhotos.git", .upToNextMajor(from: "2.0.0"))
]

And Then.

import InstagramPhotos

Usage

In your ViewController.

var picker: InstagramPhotosPickingViewController?

Photo library access

First. It is importance to do this step. Be sour your app have Authorization to access your photo library. on your plist.info adding this attribute

<key>NSPhotoLibraryUsageDescription</key>
<string>Your app need access your photo library</string>

if iOS 14 you need to set PHPhotoLibraryPreventAutomaticLimitedAccessAlert to YES on plist.info to prevent limited photos access alert.

<key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>
<true/>

Initialize your photo Pinking View Controller

private func getPickerReady() {
    picker = InstagramPhotosPickingViewController(imagePicking: self,
                                         ocalizationsProviding: InstagramPhotosChineseLocalizationProvider())
}

Present the pickingViewController

@IBAction func show(_ sender: UIButton) {
    guard let unwrapPicker = picker else { return }
    unwrapPicker.modalPresentationStyle = .fullScreen
    present(unwrapPicker, animated: true, completion: nil)
}

Get your image through InstagramPhotosPicking delegate.

extension ViewController: InstagramPhotosPicking {
    //your viewcontroller
    func instagramPhotosDidFinishPickingImage(result: InstagramPhotosPickingResult) {
        switch result {
        case .failure(let error):
            switch error {
            case .cancelByUser:
                print("User canceled selete image")
            default:
                print(error)
            }
        case .success(let ipImage):
            viewController.imageView.image = ipImage.image
        }
    }
}

Customize Localization

You could use default InstagramPhotosChineseLocalizationProvider() for English, InstagramPhotosEnglishLocalizationProvider() for Chinese.

define you own localization provider

// Exsample Korean
struct KoreanLocalizationProvider: InstagramPhotosLocalizationsProviding {
    public init() {}
    public func pinkingControllerNavigationTitle() -> String {  return "사진 선택" }
    public func pinkingControllerNavigationNextButtonText() -> String { return "다음 단계" }
    public func pinkingControllerDefaultAlbumName() -> String { return "사진 갤러리" }
    public func pinkingControllerAddingImageAccessButtonText() -> String { return "접근 가능한 사진 추가" }
    public func albumControllerNavigationTitle() -> String { return "앨범 선택" }
    public func albumControllerNavigationCancelButtonText() -> String { return "취소" }
    public func photosLimitedAccessModeText() -> String { return "액세스 권한이있는 모든 사진이 표시됩니다" }
}

Apply it in the pickingViewController Initialize

private func getPickerReady() {
    let imageProvider = PhotosProvider(viewController: self)
    picker = InstagramPhotosPickingViewController(imagePicking: imageProvider,
                                        localizationsProviding: KoreanLocalizationProvider())
}

Licenses

All source code is licensed under the MIT License.

About