Skip to content

Commit

Permalink
Fixed Bluetooth permission. Added codestyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed May 4, 2021
1 parent 7d45dec commit e6858d9
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 35 deletions.
23 changes: 23 additions & 0 deletions CODESTYLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Documentation

## Using marks

For clean struct code good is using marks.

```swift
class Example {

// MARK: - Init

init() {}
}
```

Here you find all which using in project.

- // MARK: - Init
- // MARK: - Lifecycle
- // MARK: - Layout
- // MARK: - Helpers

If you can't find valid, add new to codestyle agreements please. Other can be use if class is large and need struct it even without adding to codestyle agreements.
2 changes: 1 addition & 1 deletion SPPermissions.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SPPermissions"
s.version = "5.5.2"
s.version = "5.5.4"
s.summary = "Ask permissions on Swift. Available List, Dialog & Native interface. Can check state permission."
s.homepage = "https://github.com/ivanvorobei/SPPermissions"
s.source = { :git => "https://github.com/ivanvorobei/SPPermissions.git", :tag => s.version }
Expand Down
30 changes: 24 additions & 6 deletions SPPermissions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
F499B2092380A0A000B83B08 /* SPPermissionsNativeController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F499B2082380A0A000B83B08 /* SPPermissionsNativeController.swift */; };
F4CD097623A026BC00DF6FEF /* SPBluetoothPermission.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4CD097423A0218E00DF6FEF /* SPBluetoothPermission.swift */; };
F4CD097723A026C500DF6FEF /* SPBluetoothPermission.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4CD097423A0218E00DF6FEF /* SPBluetoothPermission.swift */; };
F4CFBFF62641240700BA1903 /* SPPermissionBluetoothHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4CFBFF52641240700BA1903 /* SPPermissionBluetoothHandler.swift */; };
F4CFBFF72641240700BA1903 /* SPPermissionBluetoothHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4CFBFF52641240700BA1903 /* SPPermissionBluetoothHandler.swift */; };
F4CFBFF92641276E00BA1903 /* CODESTYLE.md in Resources */ = {isa = PBXBuildFile; fileRef = F4CFBFF82641276E00BA1903 /* CODESTYLE.md */; };
F4CFBFFA2641276E00BA1903 /* CODESTYLE.md in Resources */ = {isa = PBXBuildFile; fileRef = F4CFBFF82641276E00BA1903 /* CODESTYLE.md */; };
F4D3CD55238D457F006C3DE2 /* SPPermissionDeniedAlertData.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D3CD53238D452B006C3DE2 /* SPPermissionDeniedAlertData.swift */; };
F4D3CD56238D457F006C3DE2 /* SPPermissionDeniedAlertData.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D3CD53238D452B006C3DE2 /* SPPermissionDeniedAlertData.swift */; };
F4EA2646236ECE040070B2BA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4EA2645236ECE040070B2BA /* AppDelegate.swift */; };
Expand Down Expand Up @@ -172,6 +176,8 @@
F499B206238087A800B83B08 /* SPPermissionsCloseButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPPermissionsCloseButton.swift; sourceTree = "<group>"; };
F499B2082380A0A000B83B08 /* SPPermissionsNativeController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPPermissionsNativeController.swift; sourceTree = "<group>"; };
F4CD097423A0218E00DF6FEF /* SPBluetoothPermission.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPBluetoothPermission.swift; sourceTree = "<group>"; };
F4CFBFF52641240700BA1903 /* SPPermissionBluetoothHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPPermissionBluetoothHandler.swift; sourceTree = "<group>"; };
F4CFBFF82641276E00BA1903 /* CODESTYLE.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CODESTYLE.md; sourceTree = "<group>"; };
F4D3CD53238D452B006C3DE2 /* SPPermissionDeniedAlertData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPPermissionDeniedAlertData.swift; sourceTree = "<group>"; };
F4EA2643236ECE030070B2BA /* Permissions iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Permissions iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
F4EA2645236ECE040070B2BA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -302,6 +308,7 @@
F4342385251CDBEB0094F319 /* LICENSE */,
F4342388251CDBEB0094F319 /* Package.swift */,
F4342389251CDBEB0094F319 /* README.md */,
F4CFBFF82641276E00BA1903 /* CODESTYLE.md */,
F4342384251CDBEB0094F319 /* SPPermissions.podspec */,
F43F8DA6236ECCEE00B94208 /* Sources */,
F4EA2644236ECE040070B2BA /* Example iOS */,
Expand Down Expand Up @@ -492,6 +499,7 @@
isa = PBXGroup;
children = (
F4EA2692236F30E70070B2BA /* SPPermissionLocationHandler.swift */,
F4CFBFF52641240700BA1903 /* SPPermissionBluetoothHandler.swift */,
);
path = Handlers;
sourceTree = "<group>";
Expand Down Expand Up @@ -702,13 +710,15 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F4CFBFFA2641276E00BA1903 /* CODESTYLE.md in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
F43F8D99236ECC9D00B94208 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F4CFBFF92641276E00BA1903 /* CODESTYLE.md in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -750,6 +760,7 @@
9E50E9D6238B24BD00B71477 /* SPPermissionsDataSource.swift in Sources */,
9E50E9E7238B24FB00B71477 /* SPPermissionsListController.swift in Sources */,
9E50E9E0238B24E300B71477 /* SPPermissionsLabel.swift in Sources */,
F4CFBFF72641240700BA1903 /* SPPermissionBluetoothHandler.swift in Sources */,
9E50E9F9238B252E00B71477 /* SPPermissionsDelay.swift in Sources */,
9E50E9D9238B24C500B71477 /* SPPermissionsControllerProtocol.swift in Sources */,
9E50E9E1238B24E500B71477 /* SPPermissionsCloseButton.swift in Sources */,
Expand Down Expand Up @@ -797,6 +808,7 @@
F4FB9E9A2379963000F7272C /* SPPermissionActionButton.swift in Sources */,
F4EA268B236F2BB90070B2BA /* SPPermissionProtocol.swift in Sources */,
F4EA267E236F2B890070B2BA /* SPCalendarPermission.swift in Sources */,
F4CFBFF62641240700BA1903 /* SPPermissionBluetoothHandler.swift in Sources */,
F4EA2661236ED1790070B2BA /* SPPermissions.swift in Sources */,
F499B2012380471100B83B08 /* SPPermissionsLabel.swift in Sources */,
F4FB9E8A2379860B00F7272C /* SPPermissionsListFooterCommentView.swift in Sources */,
Expand Down Expand Up @@ -877,7 +889,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8JMTA2AAF3;
INFOPLIST_FILE = "$(SRCROOT)/Example tvOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -898,7 +910,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8JMTA2AAF3;
INFOPLIST_FILE = "$(SRCROOT)/Example tvOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -917,8 +929,10 @@
isa = XCBuildConfiguration;
baseConfigurationReference = F4FB9E9D2379E96E00F7272C /* SPPermissionsConfiguration.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 8JMTA2AAF3;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -943,8 +957,10 @@
isa = XCBuildConfiguration;
baseConfigurationReference = F4FB9E9D2379E96E00F7272C /* SPPermissionsConfiguration.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 8JMTA2AAF3;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -1092,9 +1108,10 @@
baseConfigurationReference = F4FB9E9D2379E96E00F7272C /* SPPermissionsConfiguration.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8JMTA2AAF3;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -1120,9 +1137,10 @@
baseConfigurationReference = F4FB9E9D2379E96E00F7272C /* SPPermissionsConfiguration.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8JMTA2AAF3;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -1148,7 +1166,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8JMTA2AAF3;
INFOPLIST_FILE = "$(SRCROOT)/Example iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -1169,7 +1187,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8JMTA2AAF3;
INFOPLIST_FILE = "$(SRCROOT)/Example iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// The MIT License (MIT)
// Copyright © 2020 Ivan Vorobei (hello@ivanvorobei.by)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import UIKit
import CoreBluetooth

#if os(iOS)
class SPPermissionBluetoothHandler: NSObject, CBCentralManagerDelegate {

static let shared: SPPermissionBluetoothHandler = .init()

var manager: CBCentralManager?
var completion: SPBluetoothPermissionHandler?

override init() {
super.init()
self.manager = CBCentralManager(delegate: self, queue: nil, options: [:])
}

func centralManagerDidUpdateState(_ central: CBCentralManager) {
if #available(iOS 13.0, *) {
switch central.authorization {
case .notDetermined:
break
default:
self.completion?()
}
} else {
switch CBPeripheralManager.authorizationStatus() {
case .notDetermined:
break
default:
self.completion?()
}
}
}
}

extension SPPermissionBluetoothHandler {

typealias SPBluetoothPermissionHandler = ()->()?
}
#endif
29 changes: 1 addition & 28 deletions Sources/SPPermissions/Permissions/SPBluetoothPermission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import CoreBluetooth

class SPBluetoothPermission: NSObject, SPPermissionProtocol {

typealias SPBluetoothPermissionHandler = ()->()?
private var completion: SPBluetoothPermissionHandler?
private var manager: CBCentralManager?

var isAuthorized: Bool {
if #available(iOS 13.0, *) {
return CBCentralManager().authorization == .allowedAlways
Expand All @@ -45,31 +41,8 @@ class SPBluetoothPermission: NSObject, SPPermissionProtocol {
}

func request(completion: @escaping ()->()?) {
self.completion = completion
self.manager = CBCentralManager(delegate: self, queue: nil, options: [:])
}
}

extension SPBluetoothPermission: CBCentralManagerDelegate {

func centralManagerDidUpdateState(_ central: CBCentralManager) {
if #available(iOS 13.0, *) {
switch central.authorization {
case .notDetermined:
break
default:
self.completion?()
}
} else {
switch CBPeripheralManager.authorizationStatus() {
case .notDetermined:
break
default:
self.completion?()
}
}
SPPermissionBluetoothHandler.shared.completion = completion
}

}

#endif

0 comments on commit e6858d9

Please sign in to comment.