sparrowcode / PermissionsKit

Universal API for request permission and get its statuses.
https://x.com/sparrowcode_ios
MIT License
5.64k stars 462 forks source link

App crashes in isAllowed method in SPPermission enum #122

Closed rkyslyy closed 5 years ago

rkyslyy commented 5 years ago
Fatal error: SPPermission - Notification not import. See Readme: https://github.com/ivanvorobei/SPPermission: file /Users/*/<project name>/Carthage/Checkouts/SPPermission/Source/SPPermission/SPPermission.swift, line 89
(lldb) 

Same problem occurs on previous version (4.0), but is gone on version 3.1.1

Screen Shot 2019-06-14 at 13 44 21
TheGeekPharaoh commented 5 years ago

Also seeing this issue

ivanvorobei commented 5 years ago

Please, attach which pods you add to Podfile

rkyslyy commented 5 years ago

@ivanvorobei pod 'google-cast-sdk', '4.3.5' pod 'LGButton' pod 'FacebookCore' pod 'FacebookLogin' pod 'FacebookShare' pod 'UITextView+Placeholder' pod 'JWPlayer-SDK' pod 'VersaPlayer' pod 'MMSProfileImagePicker' pod 'YPImagePicker' pod 'Google-Mobile-Ads-SDK' pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '4.3.1'

rkyslyy commented 5 years ago

@ivanvorobei libraries from Cartfile: github "Alamofire/Alamofire" "5.0.0-beta.6" github "kishikawakatsumi/KeychainAccess" == 3.1.2 github "Skyscanner/SkyFloatingLabelTextField" github "hackiftekhar/IQKeyboardManager" == 6.0.4 github "marmelroy/PhoneNumberKit" github "mxcl/PromiseKit" ~> 6.8 github "SwiftKickMobile/SwiftMessages" github "ninjaprox/NVActivityIndicatorView" == 4.6.1 github "line/line-sdk-ios-swift" github "optonaut/ActiveLabel.swift" github "DaveWoodCom/XCGLogger" == 6.1.0 github "onevcat/Kingfisher" ~> 5.0 github "SnapKit/SnapKit" == 4.0.1 github "ReactiveX/RxSwift" ~> 5.0 github "Juanpe/SkeletonView" github "IvanVorobei/SPPermission" == 3.1.1 github "button/DeepLinkKit" github "auth0/JWTDecode.swift"

ivanvorobei commented 5 years ago

@rkyslyy I separate SPPermission to modules. Need add configuration file for allow work with Notification. See Readme section.

Also you can instal SPPermission via pods.

ivanvorobei commented 5 years ago

@rkyslyy write me about the result

sdevo619 commented 5 years ago

I am having the same issue as the guys above, after trying to install this in a new project today. Glad I found this, as this is working perfectly fine in my other project, which I believe is still on the last version on SPPermission. Any ETA on a fix for this?

Also, on a completely unrelated note, could you add a permission prompt for HomeKit too?? I have struggled with this one too, as Apple seems to handle the HomeKit Permissions a bit different. Either way, keep up the great work!!!

ivanvorobei commented 5 years ago

@sdevo619 you are added configuration file?

ivanvorobei commented 5 years ago

I am upload new version. Please, update. Wait any news. Thanks!

sdevo619 commented 5 years ago

Having this issue now with locationAlwaysAndWhenInUse, even after updating.

Screen Shot 2019-06-15 at 3 24 40 AM
ivanvorobei commented 5 years ago

@sdevo619 you rebuild project?

ivanvorobei commented 5 years ago

@sdevo619 I am create empty project and location work correctly now.

sdevo619 commented 5 years ago

Still have the same issue as before. I am running SPPermission 4.0.5, so not sure why you closed out the issue. I have all plist keys in place and have compared to my working project, so I don’t believe it’s an issues on my end. Let me know if there are any other new changes I need to be aware of. Thank you very much!!

Spencer Koltun

On Jun 15, 2019, at 4:25 AM, Ivan Vorobei notifications@github.com wrote:

Closed #122.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ivanvorobei commented 5 years ago

@sdevo619 you can create new empty project and send me?

sdevo619 commented 5 years ago

I am using a UIPagecontroller and attempting to present the SPPermission prompt on the second page of the page controller. The error and crash, is occurring directly after the UIPageController calls the a WillTransitionTo and is loading the second page. Currently, the code for launching SPPermissions, is in the second page’s view controller and running inside the viewdidappear method, but I can move it to the UIPageController View Controller if needed. I think this may be what is causing this issue. What do you advise??

Spencer Koltun

On Jun 15, 2019, at 10:29 PM, Ivan Vorobei notifications@github.com wrote:

@sdevo619 you can create new empty project and send me?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ivanvorobei commented 5 years ago

@sdevo619 Now I am sure that the problem is not with Cartfile. All permissions work correctly. Make an empty project, I will look it

sdevo619 commented 5 years ago

I’m using Cocoapods, not a cartfile. I had issues before this, trying to run SPPermissions in any other location beside viewdidappear. I think that using a page controller, may be causing this issue. I will build an empty project and see how it goes. If you have any other ideas, please let me know. My other project is using a tab bar controller, which is probably why I am not seeing this issue there.

Spencer Koltun

On Jun 16, 2019, at 5:04 AM, Ivan Vorobei notifications@github.com wrote:

@sdevo619 Now I am sure that the problem is not with Cartfile. All permissions work correctly. Make an empty project, I will look it

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

rkyslyy commented 5 years ago

@ivanvorobei 4.0.5 doesn't have this issue anymore, many thanks!

sdevo619 commented 5 years ago

Yes, it still does have the same issue. Still has not been fixed. Not sure how good your English is, but you are not understanding what I am saying. It is still regularly crashing on line 131 of the pod file with a fatal error related to the location services request. If you can’t explain why this is happening, I’m just going to go back to using normal permission requests, because that was working just fine. This is still very broken. I am happy to work with you, but claiming it is fixed, when it is clearly crashing in the same place and it is no better than before does not help me. The app I’m building needs to use location always or when in use, and to be able present SPPermissin prompt inside of a UIPageController, to work correctly, and that is where this keeps crashing. Please fix ASAP or at least tell me how to run it without crashing when inside of a UIPageController. I need a working code example at this point using a UIPageController for the root VC, as nothing I have tried is working using the based code. Thank you!

Spencer Koltun

On Jun 17, 2019, at 12:50 AM, Roman Kyslyy notifications@github.com wrote:

@ivanvorobei 4.0.5 doesn't have this issue anymore, many thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ivanvorobei commented 5 years ago

@sdevo619 please, create empty project and send me link to archive. I test it error.

I am create new project and add SPPermission. For me all work correct. Give me project or screenshoot which error you see.

ivanvorobei commented 5 years ago

@sdevo619 I think I know what the problem is with you. Attach podfile file with list all pods which you use.

ivanvorobei commented 5 years ago

@sdevo619 ?

fivenorth commented 5 years ago

Hi @ivanvorobei. I am also experiencing this bug after recently updating to your latest release. Here's the calling method from my WelcomeViewController:

Image 2019-06-28 at 2 04 35 PM

And where it's crashing in SPPermission.swift:

Image 2019-06-28 at 2 05 18 PM

This was working fine in the release I was using prior to this one. Any thoughts? I'm getting ready to deploy an update to my app and wondering if I just need to rollback to a prior version of SPPermission for now until this gets sorted out.

Here are the other pods associated with the project:

pod 'Fabric'
pod 'Crashlytics'
pod 'Alamofire'
pod 'UICKeyChainStore'
pod 'JSQCoreDataKit'
pod 'SwiftyJSON'
pod 'SwiftyTimer'
pod 'SVProgressHUD'
pod 'SPPermission'
pod 'CCBottomRefreshControl'
ivanvorobei commented 5 years ago

@fivenorth hi!

You need reed readme. It crytical update and need import modules. like this:

pod 'SPPermission/Contacts'
fivenorth commented 5 years ago

@ivanvorobei First off... that's just an awesome response time!! Can't tell you how much I appreciate that. Second, I need to do a better job of reading the README file! Sorry about that. I revised my podfile and now all seems to be well. :) Thank you!!

sdevo619 commented 5 years ago

Ivan, I created a completely empty project and copied my extension which houses all the code for the permission prompt customization. I also did not use a page controller in the empty project and still wound up with exact same error I have been reporting this whole time. I have included my extension so you can review my customizations, but this issue seems to stem from the location services prompt. Which I have all three plist entries for in my Info.plist. If any of the location services permission prompts have changed in the most recent version of iOS, I would assume it may have to do with that. It always fails on line 131, of the getMangerForPermissions function. Please let me know what else I can give you to help troubleshoot this. Thank you very much!!!

import UserNotifications import CoreLocation import SPPermission

class ViewController: UIViewController {

var shouldRunOnce = false

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    getPermissionStillNeeded()
}

}

//MARK: - Request App Permission

//MARK: - Custom Permissions extension ViewController: SPPermissionDialogDelegate, SPPermissionDialogDataSource, SPPermissionDialogColorSource{

func getPermissionStillNeeded(){

    //SPPermission.Dialog.request(with: [.camera, .microphone, .notification], on: self)

    SPPermission.Dialog.request(with:  [.locationAlwaysAndWhenInUse, .mediaLibrary, .camera, .notification], on: self, delegate: self, dataSource: self)
}

func didHide() {

    //let isAllowedNotification = SPPermission.isAllowed(.notification)

// let isAllowedLocation = SPPermission.isAllowed(.locationAlwaysAndWhenInUse) //
// if !isAllowedLocation{ //
// getPermissionStillNeeded() // } // else{ //
// //appDelegate.setupLocationManager() //
// //showWhatsNewIfNecessary(shouldUpdateKeyValueStore: true) // } }

func didAllow(permission: SPPermissionType) {
    //print("SPPermissionDialogDelegate - didAllow \(permission.name)")

}

func didDenied(permission: SPPermissionType) {
    //print("SPPermissionDialogDelegate - didDeny \(permission.name)")

    print("Permission Denied")

    // Create Alert
    let alert = UIAlertController(title: "Camera", message: "Camera access is absolutely necessary to use this part of the app", preferredStyle: .alert)

    // Add "OK" Button to alert, pressing it will bring you to the settings app
    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
        UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
    }))
    // Show the alert with animation
    DispatchQueue.main.async {
        self.present(alert, animated: true)
    }

}

var dragToDismiss: Bool {
    return true
}

var showCloseButton: Bool {
    return false
}

var allowTitle: String {
    return "Allow"
}

var allowedTitle: String {
    return "Allowed"
}

var dialogTitle: String {
    return "AWolf"
}

var dialogSubtitle: String {
    return "Permissions Request"
}

var dialogComment: String {
    return "Permissions are necessary for the the application to be able to perform all of its functions. Push are not required permissions"
}

func name(for permission: SPPermissionType) -> String? {
    switch permission {
    case .camera:
        return "Camera"
    case .photoLibrary:
        return "Photo Library"
    case .notification:
        return "Notification"
    case .microphone:
        return "Microphone"
    case .calendar:
        return "Calendar"
    case .contacts:
        return "Contacts"
    case .reminders:
        return "Reminders"
    case .speech:
        return "Speech"
    case .locationWhenInUse, .locationAlwaysAndWhenInUse:
        return "Location"
    case .motion:
        return "Motion"
    case .mediaLibrary:
        return "Media Library"
    }
}

func description(for permission: SPPermissionType) -> String? {
    switch permission {
    case .camera:
        return "Record Video and Images"
    case .calendar:
        return "Application can add events to calendar"
    case .contacts:
        return "Access for your contacts and phones"
    case .microphone:
        return "Audio Recording with Videos"
    case .notification:
        return "Notifications"
    case .photoLibrary:
        return "Access for save photos in your gallery"
    case .reminders:
        return "Application can create new task"
    case .speech:
        return "Speech Recognition in Notes"
    case .locationWhenInUse, .locationAlwaysAndWhenInUse:
        return "Locationn the map."
    case .motion:
        return "Allow reports motion and environment-related data"
    case .mediaLibrary:
        return "Allow check your media"
    }
}

func image(for permission: SPPermissionType) -> UIImage? {

    switch permission {
    case .camera:

        return UIImage(named: "camera icon perm")

    case .locationWhenInUse, .locationAlwaysAndWhenInUse:

        return UIImage(named: "map icon perm")

    case .notification:

        return UIImage(named: "notification icon perm")

    case .microphone:

        return UIImage(named: "mic icon perm")

    default:
        return nil
    }
}

func deniedTitle(for permission: SPPermissionType) -> String? {
    return "Permission denied"
}

func deniedSubtitle(for permission: SPPermissionType) -> String? {
    return "Please, go to Settings and allow permissions"
}

var cancelTitle: String {
    return "Cancel"
}

var settingsTitle: String {
    return "Settings"
}

//colors

var whiteColor: UIColor {return UIColor.black}
var blackColor: UIColor {return UIColor.blue}
var baseColor: UIColor {return UIColor.blue}
var grayColor: UIColor { return UIColor.lightGray }
var lightGrayColor: UIColor { return  colorLiteral(red: 0.1215686275, green: 0.1294117647, blue: 0.1411764706, alpha: 1) }

var iconWhiteColor: UIColor { return UIColor.blue }
var iconLightColor: UIColor { return UIColor.blue }
var iconMediumColor: UIColor {return UIColor.blue }
var iconDarkColor: UIColor {return UIColor.blue }

//    static let darkIcon = UIColor.init(red: 0/255, green: 122/255, blue: 255/255, alpha: 1)
//    static let mediumIcon = UIColor.init(red: 122/255, green: 169/255, blue: 248/255, alpha: 1)
//    static let lightIcon = UIColor.init(red: 196/255, green: 216/255, blue: 251/255, alpha: 1)

}

Spencer Koltun

On Jun 17, 2019, at 6:26 AM, Ivan Vorobei notifications@github.com wrote:

@sdevo619 please, create empty project and send me link to archive. I test it error.

I am create new project and add SPPermission. For me all work correct. Give me project or screenshoot which error you see.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ivanvorobei commented 5 years ago

@sdevo619 your instal via cocoa pods? please, attach pod-file

sdevo619 commented 5 years ago

Yes, it is a Cocoapods install. I have tried it both ways using just the SP permission pod, and I have also tried using the individual pods too. Which is the correct way to do this for iOS 12.3.1? Please let me know, what I’m missing here. Thank you for the quick response!!!

Uncomment the next line to define a global platform for your project

platform :ios, '12.2'

target 'PermissionTest' do

Comment the next line if you don't want to use dynamic frameworks

use_frameworks!

Pods for PermissionTest

pod 'SPPermission'

pod 'SPPermission/Camera' pod 'SPPermission/Contacts' pod 'SPPermission/Calendar' pod 'SPPermission/PhotoLibrary' pod 'SPPermission/Notification' pod 'SPPermission/Microphone' pod 'SPPermission/Reminders' pod 'SPPermission/SpeechRecognizer' pod 'SPPermission/Location' pod 'SPPermission/Motion' pod 'SPPermission/MediaLibrary'

target 'PermissionTestTests' do inherit! :search_paths

Pods for testing

end

target 'PermissionTestUITests' do inherit! :search_paths

Pods for testing

end

end

Spencer Koltun

On Jul 1, 2019, at 12:10 PM, Ivan Vorobei notifications@github.com wrote:

@sdevo619 your instal via cocoa pods? please, attach pod-file

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ivanvorobei commented 5 years ago

@sdevo619 create simple project with bug, zip it and link send here

sdevo619 commented 5 years ago

This is in the simulator this occurs, on an iPHone X Simulator, so this should not be hard to replicate with code I sent you already. I don’t mean to rush you, but I can’t keep waiting for this to be fixed, as I can’t test my app on a fresh install with the permission prompts not working because of this. I sent you the example extension, which is having this issue in a completely blank view controller in a fresh blank project with a single ViewController. All I did was add the extension to the project, add the plist entries, downloaded the most up to date pods, add the func to load it up in the viewdidappear. Is there an up to date, working, example, in your GitHub Repo??

Spencer Koltun

On Jul 1, 2019, at 1:08 PM, Ivan Vorobei notifications@github.com wrote:

@sdevo619 create simple project with bug, zip it and link send here

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ivanvorobei commented 5 years ago

@sdevo619 for me all work correct. I need see your project. You do not need to wait - just pack the project and send it to me. I'll find the problem myself

sdevo619 commented 5 years ago

Can you answer question regarding the proper way for the pod file to be setup in the current version. Let’s just assume, I want to access all of the permissions to keep things simple?

Spencer Koltun

On Jul 2, 2019, at 12:46 AM, Ivan Vorobei notifications@github.com wrote:

@sdevo619 for me all work correct. I need see your project. You do not need to wait - just pack the project and send it to me. I'll find the problem myself

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

sdevo619 commented 5 years ago

I think I may have found the issues in your code. In the switch statement, in the .authorizedWhenInUse case, you are requesting always authorization, instead of wheninuse authorization. I haven’t tried to change it yet, but I wanted to ask you if you thought this could be the problem.

Spencer Koltun

On Jul 2, 2019, at 12:46 AM, Ivan Vorobei notifications@github.com wrote:

@sdevo619 for me all work correct. I need see your project. You do not need to wait - just pack the project and send it to me. I'll find the problem myself

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

sdevo619 commented 5 years ago

Ivan, I finally just figured it out. My sincerest apologies for claiming it was your code. The issue was in the pod file. That was was why asked if it made a difference in my previous messages. The pod I was using, was the SPPermission one, that covered all the permissions and it was crashing. Once I removed that and changed it to all the individual ones, it works fine now. No crashes. It might not be a bad idea to notate this in case anyone else comes across this same crash. Thank you again for your help. Take care!!!

Spencer Koltun

On Jul 2, 2019, at 12:46 AM, Ivan Vorobei notifications@github.com wrote:

@sdevo619 for me all work correct. I need see your project. You do not need to wait - just pack the project and send it to me. I'll find the problem myself

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.