Parse-sdk-ios-osx: Method requires pinning enabled

Created on 25 Aug 2015  Â·  51Comments  Â·  Source: parse-community/Parse-SDK-iOS-OSX

I keep receiving this error:

'NSInternalInconsistencyException', reason: 'Method requires Pinning enabled.'

Ive looked at tons of forums but most of them pertain to an error kind of opposite to mine:

'NSInternalInconsistencyException', reason: 'Method not allowed while pinning is enabled'

I have enabled local datastore before setting the application id and client key. What should I do to resolve this?

Needs More Info

Most helpful comment

@okaris - add configuration.localDatastoreEnabled = YES inside the configuration block.
Either you are using non-configuration based methods or you need to configure the entire configuration object from inside the block.

All 51 comments

Hey @dailenspencer, this exception is only thrown if you are trying to access methods that require Local Datastore to be enabled, before Parse is setup (setApplicationId:clientKey:) if you don't have Parse.enableLocalDatastore() call.

Make sure that the code that throws the exception is called after Parse is fully setup.
If that doesn't work and you are still blocked by this - please attach a repro project/code snippet that fails for you. Without the repro - it is very hard to track down problems like this, since we don't have context on the flow of the application and what specific thing makes it throw in your case.

Thank you for your feedback. We prioritize issues that have clear and concise repro steps. Please see our Bug Reporting Guidelines about what information should be added to this issue.

In addition, you might find the following resources helpful:

  • Documentation: https://www.parse.com/docs
  • Google Groups: https://groups.google.com/forum/#!forum/parse-developers
  • Stack Overflow: http://stackoverflow.com/tags/parse.com

@nlutsenko
Okay so to be completely honest im not good with uploading files my mac is really iffy and i lost alot of files once when i uploaded through github for some reason( im a dummy). but heres two screen shots. One shows my app delegate where i enable the local datastore and the other shows my tableviewcontroller file that causes the error.

TableViewController:
screenshot 2015-08-25 14 39 14

App Delegate:
screen shot 2015-08-25 at 2 38 25 pm

Great. Thank you, that helps..
@dailenspencer, what I think happens is that your TableViewController gets initialized and loaded before application:didFinishLaunchingWithOptions: is called.
Try moving initialization of Parse SDK into application:willFinishLaunchingWithOptions: or even into init method of your AppDelegate.

@nlutsenko okay so i moved...

Parse.enableLocalDatastore()

    // Initialize Parse.
    Parse.setApplicationId("LlfYEifUnczdxWQzEgWw4kb8v7206BdAvMGkAXJP",
        clientKey: "IqPxfsX2A2U2gny328xR5gRqucHS39lJ0EPXbREJ")

    // [Optional] Track statistics around application opens.
    PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)

from didfinishlaunching to willfinishlaunching and im still receiving the same crash. I tried putting it into init after but i receive two errors

@nlutsenko
And before i actually go to the tableviewcontroller page i have to go through a log in, and main screen. Im not really super good with how execution works but wouldnt didfinishlaunchingwithoptions be executed by the time i get through both the log in and main screen?

It should, though I am not sure whether it actually does...
Can you place breakpoints and verify that Parse.setApplicationId() is actually called before the exception is being thrown?

@nlutsenko
I put a print statement and that was the first thing that printed on the console. Then it crashes with the normal error. "Set application id" is what i put in the print statement.

set application id
calling didfinishlaunching with options2015-08-25 16:07:39.432 greek[22542:505792] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Method requires Pinning enabled.'

Ok, great...
We just eliminated all possibilities that the error is on one end.
Any chance you can create a repro project for this?

Since this doesn't reproduce for me or with say, ParseUIDemo in ParseUI-iOS repo - I believe there is definetly something going on in your project setup.

@nlutsenko I can put breakpoints im just super new to this so ill have to figure it out. I figured a print statement would tell us that it was in fact executed before the error

Yes. where would i find instructions on that?

The thing is that I believe the exception is being thrown on the background thread and propagates to the main thread, since you see the log statement and then the exception is being thrown. That's why looking through stack trace or exception would be actually really helpful.
Side question: What errors do you see when you put it inside init method on AppDelegate?

instructions on that - you mean the repro project or ParseUI?
ParseUI can be found here.

screenshot 2015-08-25 16 16 48

It should something like this:

    override init() {
        super.init();

        Parse.enableLocalDatastore()
        ....
    }

Also - keep the PFAnalytics call in applicationDidFinishLaunchingWithOptions

I tried it. Still got the same crash. im going to upload the project now I just have never done it before so its going to take me a second

:+1:

@nlutsenko okay so i pushed the project to a repo on my profile called "greek_remastered". I hope i did it right and you can view it now. if not, let me know what i need to do so you can view it

@dailenspencer, as sad as it sounds - that repo looks completely empty, or rather - no code inside of it that is using Parse or anything.

@nlutsenko i got it!! the files are on there. go take a look and let me know if you can figure anything out. thanks again i really appreciate your help

@dailenspencer Can you provide me with a test email/password for that application?
Feel free to send privately to [email protected]

username: [email protected]
password: cabbagepatch

you may have to uncomment the enable local datastore and the
eventboardtableviewcontroller pinning functions

Sent with MailTrack
https://mailtrack.io/install?source=signature&lang=en&[email protected]&idSignature=22

On Tue, Aug 25, 2015 at 10:56 PM, Nikita Lutsenko [email protected]
wrote:

@dailenspencer https://github.com/dailenspencer Can you provide me with
a test email/password for that application?
Feel free to send privately to [email protected]

—
Reply to this email directly or view it on GitHub
https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/issues/107#issuecomment-134802277
.

Hey @dailenspencer,
Just logged in and went through the flow at least 5 times, including uncommenting enableLocalDatastore and pinning on EventBoardTableViewController. I am so sorry, but I can't seem to reproduce the crash.
Any chance you can outline a flow in which this crashes for you, so I can follow step-by-step?

@nlutsenko
okay i dont know if this makes things more complicated but i found something else weird going on. I went back and uncommented those three functions in eventboardtableviewcontroller.swift( basequery, queryfortable, and refreshlocaldatastorefromserver). and i left the queryfortable uncommented. I kept the Parse.EnableLocalDatastore uncommented and now when i try to log in, it just stays on the same page and doesn't segue to the main screen. when i click log in it shows the loading circle in the top bar of the iphone so i know its sending a request to parse but its not actually seguing to the main screen

As for the crash, i enabled the local datastore, left the first queryfortable commented and the next three functions uncommented. I run the program, it goes straight to the main screen without me having to log in because ive already logged in previously, and then when i click on eventboard, it crashes with the usual pinning enabled error.

Hey @dailenspencer, no matter how hard I try - I don't think I can reproduce the issue.
Any chance you can get me a step by step instructions?
Also, I would suggest trying to clean your Xcode DerivedData as well as fully resetting the simulator.

@nlutsenko Deleted the deriveddata folder. no change. Anytime I run the simulator, or run it on an actual device, it will usually just crash as soon as it is loaded. Sometimes it will wait until i click on event board. This only occurs when i uncomment Parse.enablelocaldatastore. Do you think its an issue with the frameworks?

Hey @dailenspencer, I don't think it's related to Parse SDK by itself, but rather related to usage of the SDK. Let's try further - is there anything that involves changing cache policy on queries? Or the only piece that involves queries is either only network (no cache policy set/changed) or by using fromLocalDatastore()?

I dont think I understand. Are there methods that change the cache policy of queries. If so, I dont think ive used any of those.

@nlutsenko I havent used any localdatastore methods in my project besides the one im attempting to use in the eventboardtableviewcontroller.

@nlutsenko its this fromlocaldatastore thats causing it i think
screen shot 2015-08-28 at 12 06 41 pm

I've read the thread and I'm having the same issue.

I am changing my cache policy when I try to fetch data from the network.

I have the enableLocalDataStore line in the right place and everything else works fine except that I get the error saying that pinning should be enabled.

I fixed it.

It was actually as @nlutsenko mentioned, that initialization of instance variables defined outside initializers in ViewControllers, are instantiated before calling the delegates in the AppDelegate file.

I just moved them to the right place and now I made sure that no ghost initialization of nothing that requires Parse is happening outside any function.

@jasancu
I moved any initializations of instance variables that user parse, into viewdidload. But im still receiving the same error. The only initializers i have outside of functions that even mention parse, are ones like these....
screenshot 2015-08-31 12 03 15

Could that still be causing the error? If so, how am i supposed to create a user variable that i can use throughout the entire swift file without initializing it outside of a function like above?

@dailenspencer:

I don't think that's the reason for your error.

I recommend that you do the following:

add a println() instruction to every line where you use a reference to Parse with some context like
println("Profile class:: user:PFUser ")

and so on, that way you know for sure that the setting of enabling local data store is happening before any unwanted access to information in Parse data.

@jasancu
i put print statements at my parse calls. The only print statements that execute before the crash are the ones i placed right after enabling local datastore and setting the client and application id. Thats really strange to me. Why would it be setting the app id and enabling local datastore and then throwing me that error?

  1. Can you use the app without local data store?
    Try to use the app without local data store to see if the issue is strictly related to local data store
  2. If the issue still persists, then it might be related to something else ( wrong Parse SDK?, wrong appId?)
  3. If the issue goes away then start a new project and with Parse from zero and try to reproduce the error.
  4. If you still have issues, try setting up a Parse Demo project like this: https://parse.com/tutorials/using-the-local-datastore to see if the problem still persists.
  5. if none of that works, send me a join.me and share your screen with me so I can look at it.

This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.

I am having the same issue.

The problem in my case stems from the fact that viewcontrollers in a storyboard (OS X in my case) do not only get initialized but also have their viewDidAppear method called before the AppDelegate's applicationDidFinishLaunching (or the "WillFinish" variant even).

Therefore I'd say that the Parse SDK's requirement of doing stuff in applicationDidFinishLaunching is not really solid advice and should be improved. Maybe put all that stuff in the AppDelegate's init() by default? This works in my case.

I have also filed a bug with Apple since the order of the callbacks is not really intuitive or as their names would suggest.

You are right - that's why I mentioned that moving all the way to initializer of your AppDelegate might be required.

The rule of thumb here is to make sure Parse.setApplicationId(..., clientKey:...) is called before any other calls to Parse SDK.

This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.

Hey guys, since the problem looks like to be fixed I am going to close out this issue.
Feel free to reopen/comment if we missed anything here or you need any help.

@dailenspencer Hey so did you fixed your code? I'm having the exact same issue since I have a TableView too and I'm trying to enable push notifications too, Thanks!

I am still having this issue. If I use setApplicationId:clientKey: everything works fine. But if i use initializeWithConfiguration: I get the error _Method requires Pinning enabled._

I tried moving the code to application:willFinishLaunchingWithOptions: but it didn't help either.

Code:

[Parse enableLocalDatastore];

NSString *server = @"https://api.parse.com/1";
    NSString *apiURLString = @"api.mysite.com";
    NSURL *apiURL = [NSURL URLWithString:apiURLString];
    NSError *error;
    NSString * ParseAPIEndpointURL = [NSString stringWithContentsOfURL:apiURL encoding:NSUTF8StringEncoding error:&error];

if ([NSURL URLWithString:ParseAPIEndpointURL]) {

    server = ParseAPIEndpointURL;

    NSLog(@"Got a valid URL for API:%@", server);


}else{

    NSLog(@"Did not get a valid URL for API, sticking with the default:%@", server);


}

ParseClientConfiguration *parseClientConfiguration = [ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration>  _Nonnull configuration) {

    [configuration setApplicationId:@"EINK1tDxvHej25MQJaO2a7swW64NEgi7o41YF3mO"];
    [configuration setClientKey:@"qG9qj1LOs6fUCu5AQixQSFU9tAv4zqL9cN8BJ1c8"];
    [configuration setServer:server];

}];

[Parse initializeWithConfiguration:parseClientConfiguration];`

@okaris - add configuration.localDatastoreEnabled = YES inside the configuration block.
Either you are using non-configuration based methods or you need to configure the entire configuration object from inside the block.

@nlutsenko thank you! Figured that out minutes before your response. I hope it will help someone else here.

@nlutsenko configuration.localDatastoreEnabled = YES works for me. Thanks a lot.

Meanwhile, in Swift:

ParseMutableClientConfiguration.localDatastoreEnabled = true

Minor change in the iOS 1.17.1 SDK:

ParseMutableClientConfiguration.isLocalDatastoreEnabled = true

It would be great if this was reflected in the documentation https://docs.parseplatform.org/ios/guide/#app-extensions

@djruss70 the docs are on their own repo, and each section has a link to edit the page. Would you be able to follow through?

Before I go updating documents, can I confirm that the initialisation procedure that I have used is correct? Parse.setApplicationId() is replaced by Parse.initialize() with a configuration object that specifies additional parameters (including the server URL and isLocalDataStoreEnabled). It seems that Parse.setApplicationId() should be deprecated.

AppDelegate.swift:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        MyPFSubclass.registerSubclass()

        let parseConfig = ParseClientConfiguration {
            $0.isLocalDatastoreEnabled = true
            $0.applicationId = parseApplicationId
            $0.clientKey = parseClientKey
            $0.server = parseServerUrlString
        }
        Parse.initialize(with: parseConfig)

        return true
    }

This looks correct indeed

Was this page helpful?
0 / 5 - 0 ratings