Skip to content

Commit

Permalink
Update to 3.0.8
Browse files Browse the repository at this point in the history
Fix bug for denied `.locationAlways`. Update default text for location permissions. Now reload buttons when user return to app. Update example & Readme.
  • Loading branch information
ivanvorobei committed May 10, 2019
1 parent 131a1f9 commit f214f11
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 47 deletions.
12 changes: 6 additions & 6 deletions Example/SPPermission.xcodeproj/project.pbxproj
Expand Up @@ -29,7 +29,7 @@
F4C55E0E227A221C00CBA1C3 /* SPRequestPermissionLocationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4C55DFA227A221C00CBA1C3 /* SPRequestPermissionLocationHandler.swift */; };
F4FADBF5225379E70027C912 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F4FADB33225379E60027C912 /* LaunchScreen.storyboard */; };
F4FADBF6225379E70027C912 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FADB34225379E60027C912 /* AppDelegate.swift */; };
F4FADC80225379E70027C912 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FADBF1225379E70027C912 /* ViewController.swift */; };
F4FADC80225379E70027C912 /* Controller.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FADBF1225379E70027C912 /* Controller.swift */; };
F4FADC81225379E70027C912 /* Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FADBF2225379E70027C912 /* Delegate.swift */; };
F4FADC82225379E70027C912 /* ColorSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FADBF3225379E70027C912 /* ColorSource.swift */; };
F4FADC83225379E70027C912 /* DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FADBF4225379E70027C912 /* DataSource.swift */; };
Expand Down Expand Up @@ -181,7 +181,7 @@
F4FADB2C225379AF0027C912 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F4FADB33225379E60027C912 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
F4FADB34225379E60027C912 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
F4FADBF1225379E70027C912 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
F4FADBF1225379E70027C912 /* Controller.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Controller.swift; sourceTree = "<group>"; };
F4FADBF2225379E70027C912 /* Delegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Delegate.swift; sourceTree = "<group>"; };
F4FADBF3225379E70027C912 /* ColorSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorSource.swift; sourceTree = "<group>"; };
F4FADBF4225379E70027C912 /* DataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSource.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -443,7 +443,7 @@
F4FADBF0225379E70027C912 /* Controllers */ = {
isa = PBXGroup;
children = (
F4FADBF1225379E70027C912 /* ViewController.swift */,
F4FADBF1225379E70027C912 /* Controller.swift */,
F4FADBF2225379E70027C912 /* Delegate.swift */,
F4FADBF3225379E70027C912 /* ColorSource.swift */,
F4FADBF4225379E70027C912 /* DataSource.swift */,
Expand Down Expand Up @@ -1103,7 +1103,7 @@
F4FADD9E22537A6E0027C912 /* SPConstraints.swift in Sources */,
F4FADD9622537A6E0027C912 /* SPUIImageViewExtenshion.swift in Sources */,
F4FADD6822537A6E0027C912 /* SPVideoPlayer.swift in Sources */,
F4FADC80225379E70027C912 /* ViewController.swift in Sources */,
F4FADC80225379E70027C912 /* Controller.swift in Sources */,
F4FADD4E22537A6E0027C912 /* SPImageTableViewCell.swift in Sources */,
F4FADD9A22537A6E0027C912 /* SPApp.swift in Sources */,
F4FADD8722537A6E0027C912 /* SPUIViewExtenshion.swift in Sources */,
Expand Down Expand Up @@ -1256,7 +1256,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8JMTA2AAF3;
INFOPLIST_FILE = SPPermission/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -1275,7 +1275,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8JMTA2AAF3;
INFOPLIST_FILE = SPPermission/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
2 changes: 1 addition & 1 deletion Example/SPPermission/App/AppDelegate.swift
Expand Up @@ -6,7 +6,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.launch(rootController: ViewController())
self.launch(rootController: Controller())
return true
}

Expand Down
2 changes: 1 addition & 1 deletion Example/SPPermission/Controllers/ColorSource.swift
Expand Up @@ -21,7 +21,7 @@

import UIKit

extension ViewController: SPPermissionDialogColorSource {
extension Controller: SPPermissionDialogColorSource {

/*
For customize colors ovveride more parametrs.
Expand Down
Expand Up @@ -21,7 +21,7 @@

import UIKit

class ViewController: SPController {
class Controller: SPController {

@objc func presentPermissonDialog() {

Expand Down
8 changes: 5 additions & 3 deletions Example/SPPermission/Controllers/DataSource.swift
Expand Up @@ -21,7 +21,7 @@

import UIKit

extension ViewController: SPPermissionDialogDataSource {
extension Controller: SPPermissionDialogDataSource {

var dragEnabled: Bool {
return true
Expand Down Expand Up @@ -73,8 +73,10 @@ extension ViewController: SPPermissionDialogDataSource {
return "Reminders"
case .speech:
return "Speech"
case .locationWhenInUse, .locationAlwaysAndWhenInUse:
return "Location"
case .locationWhenInUse:
return "Location When Use"
case .locationAlwaysAndWhenInUse:
return "Location Always"
case .motion:
return "Motion"
case .mediaLibrary:
Expand Down
2 changes: 1 addition & 1 deletion Example/SPPermission/Controllers/Delegate.swift
Expand Up @@ -21,7 +21,7 @@

import UIKit

extension ViewController: SPPermissionDialogDelegate {
extension Controller: SPPermissionDialogDelegate {

func didHide() {
print("SPPermissionDialogDelegate - didHide")
Expand Down
Expand Up @@ -132,10 +132,13 @@ public class SPPermissionDialogController: UIViewController {
self.setupPanGesture()
self.animator = UIDynamicAnimator(referenceView: self.view)

NotificationCenter.default.addObserver(self, selector: #selector(self.applicationDidBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)

self.updateLayout(with: self.view.frame.size)
}

@objc func request(with button: UIButton) {

var permission: SPPermissionType?
var permissionView: SPPermissionDialogLineView?

Expand All @@ -149,6 +152,18 @@ public class SPPermissionDialogController: UIViewController {

if let permission = permission {
SPPermission.request(permission, with: {

// Update `.locationWhenInUse` if allowed `.locationAlwaysAndWhenInUse`
if permission == .locationAlwaysAndWhenInUse {
if self.permissions.contains(.locationWhenInUse) {
for view in self.areaView.views {
if view.permission == .locationWhenInUse {
view.updateStyle()
}
}
}
}

if SPPermission.isAllowed(permission) {
self.delegate?.didAllow?(permission: permission)
permissionView?.updateStyle()
Expand Down Expand Up @@ -187,6 +202,12 @@ public class SPPermissionDialogController: UIViewController {
}
}

@objc func applicationDidBecomeActive() {
for view in self.areaView.views {
view.updateStyle()
}
}

func present(on viewController: UIViewController) {
self.animator.removeAllBehaviors()
self.areaView.alpha = 0
Expand Down Expand Up @@ -330,13 +351,13 @@ public class SPPermissionDialogController: UIViewController {
return CGPoint(x: self.view.center.x, y: self.view.center.y)
}

//MARK: - animator
//MARK: - Animator
var animator = UIDynamicAnimator()
var attachmentBehavior : UIAttachmentBehavior!
var gravityBehaviour : UIGravityBehavior!
var snapBehavior : UISnapBehavior!

//MARK: - handle gesture
//MARK: - Handle Gesture
@objc func handleGesture(sender: AnyObject) {
let myView = self.areaView
let location = sender.location(in: view)
Expand Down Expand Up @@ -371,10 +392,14 @@ public class SPPermissionDialogController: UIViewController {
self.hide(withDialog: true)
}

//MARK: - other
//MARK: - Other
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

deinit {
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
}
}

extension SPPermissionDialogController {
Expand Down
Expand Up @@ -37,14 +37,10 @@ class SPPermissionAlwaysAuthorizationLocationHandler: NSObject, CLLocationManage
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {

if whenInUseNotRealChangeStatus {
if status == .authorizedWhenInUse {
return
}
}
print("locationManager \(status)")

if status == .notDetermined {
print("2")
return
}

Expand All @@ -64,12 +60,10 @@ class SPPermissionAlwaysAuthorizationLocationHandler: NSObject, CLLocationManage
case .notDetermined:
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
break
case .authorizedWhenInUse:
self.whenInUseNotRealChangeStatus = true
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
break
self.whenInUseNotRealChangeStatus = true
default:
completionHandler(self.isAuthorized)
}
Expand Down
Expand Up @@ -54,8 +54,10 @@ import UIKit
return "Reminders"
case .speech:
return "Speech"
case .locationWhenInUse, .locationAlwaysAndWhenInUse:
return "Location"
case .locationWhenInUse:
return "Location When Use"
case .locationAlwaysAndWhenInUse:
return "Location Always"
case .motion:
return "Motion"
case .mediaLibrary:
Expand Down
10 changes: 5 additions & 5 deletions README.md
@@ -1,6 +1,6 @@
# SPPermission

Request permissions **with native dialog** UI and interactive animations. Also you can request permissions without dialog. Check state any permission. You can start using this project with just two lines of code and easy customisation. You can watch how I design UI for this pod [on YouTube](https://youtu.be/1mDdX7fQRv4). If you like the project, do not forget to **put star ★**
**Request permissions with dialog**. You can request many permission at once. Fast start using - type two lines of code. I do UI of dialog in Apple style. Watch how I design UI for this pod [on YouTube](https://youtu.be/1mDdX7fQRv4). If you like the project, do not forget to **put star ★**

### Preview

Expand All @@ -17,8 +17,8 @@ Request permissions **with native dialog** UI and interactive animations. Also y
- [Colors](#colors)
- [Delegate](#delegate)
- [Purpose String in Info.plist](#purpose-string-in-infoplist)
- [Screen record with design](#screen-record-with-design)
- [Other Projects (+gif)](#my-projects)
- [How I do UI](#how-i-do-UI)
- [Other Projects +gif](#my-projects)
- [SPStorkController](#spstorkcontroller)
- [SPAlert](#spalert)
- [SPLarkController](#splarkcontroller)
Expand Down Expand Up @@ -204,9 +204,9 @@ SPPermission uses many permissions in one library; you need to add some strings
Do not use the description as the name of the key - this causes errors in the latest version of the new Xcode. Specify `For SPPermission` in the description.
If I forgot to mention some, please let me know and create [issue](https://github.com/IvanVorobei/SPPermission/issues) or [pull request](https://github.com/IvanVorobei/SPPermission/pulls).

## Screen record with design
## How I do UI

I have [YouTube channel](http://youtube.com/ivanvorobei) where I publish videos about Xcode and Design. You can see how I develop native design for `SPPermission` dialog view:
I develop `SPPermission` in Apple-way. For this, I check 30 apps to get UI-elements for it project. I am take screenshoot and draw it in Sketch. For example, `Allow` button is similar to `Get` button in the AppStore. Check [timelapse](https://youtu.be/1mDdX7fQRv4) to see how I am design `SPPermission`:

[![Timelaps on YouTube](https://github.com/IvanVorobei/SPPermission/blob/master/Resources/YouTube.jpg)](https://youtu.be/1mDdX7fQRv4)

Expand Down
2 changes: 1 addition & 1 deletion SPPermission.podspec
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SPPermission"
s.version = "3.0.6"
s.version = "3.0.8"
s.summary = "Request permissions with native dialog UI and interactive animations. Check state any permission."
s.homepage = "https://github.com/IvanVorobei/RequestPermission"
s.source = { :git => "https://github.com/IvanVorobei/RequestPermission.git", :tag => s.version }
Expand Down
Expand Up @@ -132,10 +132,13 @@ public class SPPermissionDialogController: UIViewController {
self.setupPanGesture()
self.animator = UIDynamicAnimator(referenceView: self.view)

NotificationCenter.default.addObserver(self, selector: #selector(self.applicationDidBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)

self.updateLayout(with: self.view.frame.size)
}

@objc func request(with button: UIButton) {

var permission: SPPermissionType?
var permissionView: SPPermissionDialogLineView?

Expand All @@ -149,6 +152,18 @@ public class SPPermissionDialogController: UIViewController {

if let permission = permission {
SPPermission.request(permission, with: {

// Update `.locationWhenInUse` if allowed `.locationAlwaysAndWhenInUse`
if permission == .locationAlwaysAndWhenInUse {
if self.permissions.contains(.locationWhenInUse) {
for view in self.areaView.views {
if view.permission == .locationWhenInUse {
view.updateStyle()
}
}
}
}

if SPPermission.isAllowed(permission) {
self.delegate?.didAllow?(permission: permission)
permissionView?.updateStyle()
Expand Down Expand Up @@ -187,6 +202,12 @@ public class SPPermissionDialogController: UIViewController {
}
}

@objc func applicationDidBecomeActive() {
for view in self.areaView.views {
view.updateStyle()
}
}

func present(on viewController: UIViewController) {
self.animator.removeAllBehaviors()
self.areaView.alpha = 0
Expand Down Expand Up @@ -330,13 +351,13 @@ public class SPPermissionDialogController: UIViewController {
return CGPoint(x: self.view.center.x, y: self.view.center.y)
}

//MARK: - animator
//MARK: - Animator
var animator = UIDynamicAnimator()
var attachmentBehavior : UIAttachmentBehavior!
var gravityBehaviour : UIGravityBehavior!
var snapBehavior : UISnapBehavior!

//MARK: - handle gesture
//MARK: - Handle Gesture
@objc func handleGesture(sender: AnyObject) {
let myView = self.areaView
let location = sender.location(in: view)
Expand Down Expand Up @@ -371,10 +392,14 @@ public class SPPermissionDialogController: UIViewController {
self.hide(withDialog: true)
}

//MARK: - other
//MARK: - Other
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

deinit {
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
}
}

extension SPPermissionDialogController {
Expand Down
Expand Up @@ -37,14 +37,10 @@ class SPPermissionAlwaysAuthorizationLocationHandler: NSObject, CLLocationManage
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {

if whenInUseNotRealChangeStatus {
if status == .authorizedWhenInUse {
return
}
}
print("locationManager \(status)")

if status == .notDetermined {
print("2")
return
}

Expand All @@ -64,12 +60,10 @@ class SPPermissionAlwaysAuthorizationLocationHandler: NSObject, CLLocationManage
case .notDetermined:
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
break
case .authorizedWhenInUse:
self.whenInUseNotRealChangeStatus = true
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
break
self.whenInUseNotRealChangeStatus = true
default:
completionHandler(self.isAuthorized)
}
Expand Down
6 changes: 4 additions & 2 deletions Source/SPPermission/SPPermissionType.swift
Expand Up @@ -54,8 +54,10 @@ import UIKit
return "Reminders"
case .speech:
return "Speech"
case .locationWhenInUse, .locationAlwaysAndWhenInUse:
return "Location"
case .locationWhenInUse:
return "Location When Use"
case .locationAlwaysAndWhenInUse:
return "Location Always"
case .motion:
return "Motion"
case .mediaLibrary:
Expand Down

0 comments on commit f214f11

Please sign in to comment.