Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KY1VSTAR committed Apr 12, 2019
1 parent 42852e3 commit 68c6000
Showing 1 changed file with 76 additions and 114 deletions.
190 changes: 76 additions & 114 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,175 +1,137 @@
# CustomBrowserKit
# PiPhone

[![CI Status](http://img.shields.io/travis/ky1vstar/CustomBrowserKit.svg?style=flat)](https://travis-ci.org/ky1vstar/CustomBrowserKit)
[![Version](https://img.shields.io/cocoapods/v/CustomBrowserKit.svg?style=flat)](http://cocoapods.org/pods/CustomBrowserKit)
[![License](https://img.shields.io/cocoapods/l/CustomBrowserKit.svg?style=flat)](http://cocoapods.org/pods/CustomBrowserKit)
[![Platform](https://img.shields.io/cocoapods/p/CustomBrowserKit.svg?style=flat)](http://cocoapods.org/pods/CustomBrowserKit)
[![Version](https://img.shields.io/cocoapods/v/CustomBrowserKit.svg?style=flat)](http://cocoapods.org/pods/PiPhone)
[![License](https://img.shields.io/cocoapods/l/CustomBrowserKit.svg?style=flat)](http://cocoapods.org/pods/PiPhone)
[![Platform](https://img.shields.io/cocoapods/p/CustomBrowserKit.svg?style=flat)](http://cocoapods.org/pods/PiPhone)

CustomBrowserKit is a library designed to provide ability to open links in browser besides Safari to your awesome app's users. It is written in Objective-C and extended with Swift.
PiPhone is a framework that drops in picture-in-picture support (user-initiated playback of video in a floating, resizable window) for iPhone devices. It's designed to mimic default `AVPictureInPictureController` behavior as much as possible.

## Supported browsers
## Overview

CustomBrowserKit currently supports:
<p align="center">
<img width="281" height="500" src="https://github.com/ky1vstar/PiPhone/blob/master/Demonstration/PiPhone.gif?raw=true">
</p>

* [Google Chrome](https://itunes.apple.com/app/id535886823)
* [Firefox](https://itunes.apple.com/app/id989804926)
* [Opera Mini](https://itunes.apple.com/app/id363729560)
* [UC Browser](https://itunes.apple.com/app/id1048518592)
* [Puffin Web Browser](https://itunes.apple.com/app/id472937654)
* [Yandex Browser](https://itunes.apple.com/app/id483693909)
* Opening links in `SFSafariViewController` if iOS version is 9.0+
* Safari
## Features
- [x] Picture in picture support for devices that doesn't support it by default
- [x] No additional work required if `AVPictureInPictureController` have been already configured
- [x] Same appearance as default one
- [x] Handling video size changing
- [x] Handling video errors
- [x] Supports tap, double tap, pinch and pan gestures
- [x] Mimic `AVPictureInPictureControllerDelegate` behavior

## Requirements

* Xcode 8.0+
* iOS 8.0+
* Swift 3.1+
* iOS 9.0+

## Installation

CustomBrowserKit is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
PiPhone is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile:

```ruby
pod 'CustomBrowserKit'
pod 'PiPhone'
```

Also, starting with iOS 9.0 you must declare the URL schemes of external apps you want to launch. There are only two available browsers you can use without declaring appropriate URL schemes: `BKBrowserInAppSafari` and `BKBrowserSafari`. So if you want to use another browsers you must add the [LSApplicationQueriesSchemes](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/plist/info/LSApplicationQueriesSchemes) key to your app's Info.plist file. You are not required to add all of this schemes below, only those you want to let your users to use. But it is important to add BOTH schemes for browsers which have two of them. For example if you want to use Google Chrome, you have to declare both `googlechrome` and `googlechromes` URL schemes.
## Usage

To display video in picture-in-picture mode you can use both `AVPlayerViewController` and any custom video player [configured to be diplayed in picture-in-picture](https://developer.apple.com/documentation/avkit/adopting_picture_in_picture_in_a_custom_player "configured to be diplayed in picture-in-picture").

Basically you don't need to perform any additional actions, your video players support picture-in-picture now! But `PiPhone` provides some customizations that you can find useful.

| Browser | URL Schemes |
|--------------------|-------------------------------------|
| Google Chrome | `googlechrome`<br />`googlechromes` |
| Firefox | `firefox` |
| Opera | `opera` |
| UC Browser | `ucbrowser` |
| Puffin Web Browser | `puffin`<br />`puffins` |
| Yandex Browser | `yandexbrowser-open-url` |
Make sure to import the framework header: `#import <PiPhone/PiPhone.h>` for Objective-C or `import PiPhone` for Swift.

## Usage
### Content inset adjustment behavior

Make sure to import the framework header: `#import <CustomBrowserKit/CustomBrowserKit.h>` for Objective-C or `import CustomBrowserKit` for Swift.
Default `AVPictureInPictureController` behavior is to find the topmost `UINavigationController`'s bar, `UITabBarController`'s bar, `safeAreaInsets`, etc and determine where to place overlay video based on this metrics. Since imitation of this behavior turned out to be complicated and tricky process, it've been decided to control overlay video position based on predefined configurations.

### Obtaining information about browser
**Objective-C**
```objectivec
BKBrowser browser = BKBrowserFirefox;
NSString *browserName = BKBrowserGetName(browser); // @"Firefox"
UIImage *browserLogo = BKBrowserGetThumbnail(browser); // UIImage of size 100x100
```
**PiPManagerContentInsetAdjustmentNavigationBar**
Includes safe area insets and additional 44dp (32dp on landscape) inset from top safe area.

**Swift**
```swift
let browser = BKBrowser.firefox
let browserName = browser.name // "Firefox"
let browserLogo = browser.thumbnail // UIImage of size 100x100
```
**PiPManagerContentInsetAdjustmentTabBar**
Includes safe area insets and additional 49dp (32dp on landscape in iOS 11 and above) inset from bottom safe area.

### Obtaining list of available browsers
**Objective-C**
```objectivec
for (NSNumber *wrappedBrowser in BKManager.availableBrowsers) {
BKBrowser browser = (BKBrowser)wrappedBrowser.intValue;
NSLog(@"%@ is available", BKBrowserGetName(browser));
}
```
**PiPManagerContentInsetAdjustmentNavigationAndTabBars**
Includes both `PiPManagerContentInsetAdjustmentNavigationBar` and `PiPManagerContentInsetAdjustmentTabBar`.

**Swift**
```swift
for browser in BKManager.availableBrowsers {
print("\(browser.name) is available")
}
```
**PiPManagerContentInsetAdjustmentSafeArea**
Includes safe area insets.

**PiPManagerContentInsetAdjustmentNone**
Overlay video is pinned to screen edges.

This behavior can be changed via `PiPManager`'s `contentInsetAdjustmentBehavior` property.

### Opening links in specific browser
**Objective-C**
```objectivec
NSURL *url = [NSURL URLWithString:@"https://google.com/"];
PiPManager.contentInsetAdjustmentBehavior = PiPManagerContentInsetAdjustmentNavigationAndTabBars;

if ([BKManager openURL:url withBrowser:BKBrowserOpera]) {
NSLog(@"did open url successfully");
} else {
NSLog(@"did fail to open url");
}
// animated
[UIView animateWithDuration:0.25 animations:^{
PiPManager.contentInsetAdjustmentBehavior = PiPManagerContentInsetAdjustmentNavigationAndTabBars;
}];
```
**Swift**
```swift
let url = URL(string: "https://google.com/")!
PiPManager.contentInsetAdjustmentBehavior = .navigationAndTabBars
if BKManager.open(url, with: .opera) {
print("did open url successfully")
} else {
print("did fail to open url")
// animated
UIView.animate(withDuration: 0.25) {
PiPManager.contentInsetAdjustmentBehavior = .navigationAndTabBars
}
```

### Opening links in specific browser with fallback to another browser if needed
### Additional content insets

Also you can set extra spacing from screen edges to overlay video which will be added to automatically calculated one.

**Objective-C**
```objectivec
NSURL *url = [NSURL URLWithString:@"https://google.com/"];
PiPManager.additionalContentInsets = UIEdgeInsetsMake(20, 10, 20, 10);

// BKManager will try to open URL in Opera. If Opera Mini turns out to not be installed or available, BKManager will try to open URL in Google Chrome.
if ([BKManager openURL:url withBrowser:BKBrowserOpera fallbackToBrowser:BKBrowserChrome]) {
NSLog(@"did open url successfully");
} else { // if both Opera Mini and Google Chrome are not available
NSLog(@"did fail to open url");
}
// animated
[UIView animateWithDuration:0.25 animations:^{
PiPManager.additionalContentInsets = UIEdgeInsetsMake(20, 10, 20, 10);
}];
```
**Swift**
```swift
let url = URL(string: "https://google.com/")!
PiPManager.additionalContentInsets.top = 20
// BKManager will try to open URL in Opera. If Opera Mini turns out to not be installed or available, BKManager will try to open URL in Google Chrome.
if BKManager.open(url, with: .opera, fallbackTo: .chrome) {
print("did open url successfully")
} else { // if both Opera Mini and Google Chrome are not available
print("did fail to open url")
// animated
UIView.animate(withDuration: 0.25) {
PiPManager.additionalContentInsets.top = 20
}
```

### Saving `BKBrowser` to `NSUserDefaults`
### Disable picture-in-picture

You can temporarily disable picture-in-picture mode causing `AVPictureInPictureController`'s `isPictureInPicturePossible` property to be `false`.

**Objective-C**
```objectivec
BKBrowser browser = BKBrowserUCBrowser;
NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults;

// saving
[userDefaults setObject:BKBrowserGetIdentifier(browser) forKey:@"savedBrowser"];

// restoring
NSString *browserIdentifier = [userDefaults stringForKey:@"savedBrowser"];
BKBrowser savedBrowser;
if (browserIdentifier) {
savedBrowser = BKBrowserFromIdentifier(browserIdentifier);
} else {
savedBrowser = BKBrowserInAppSafari;
}
// enable
PiPManager.pictureInPicturePossible = YES;

// disable
PiPManager.pictureInPicturePossible = NO;
```

**Swift**
```swift
let browser = BKBrowser.ucBrowser
let userDefault = UserDefaults.standard
// saving
userDefault.set(browser.identifier, forKey: "savedBrowser")
// restoring
let savedBrowser: BKBrowser
if let browserIdentifier = userDefault.string(forKey: savedBrowser) {
savedBrowser = BKBrowser(identifier: browserIdentifier)
} else {
savedBrowser = .inAppSafari
}
// enable
PiPManager.isPictureInPicturePossible = true

// disable
PiPManager.isPictureInPicturePossible = false
```

## Example

To run the example project, clone the repo, and run `pod install` from the Example directory first. Example project includes both Objective-C and Swift versions.
To run the example project, clone the repo, and run `pod install` from the Example directory first.

## License

Expand Down

0 comments on commit 68c6000

Please sign in to comment.