1

I am trying to download a few strings from parse.com inside of a Notification Center widget.
Therefore I first need to sign the user in to parse. First I am loading the credentials, which are saved from the app itself in the NSUserDefaults (I know about the safety aspect.). This step works fine, but when I am performing the following code, the widget says, that the loading of data is not possible.

    func signUserIn(username: String, password: String) {
    PFUser.logInWithUsernameInBackground(username, password:password) {
        (user: PFUser!, error: NSError!) -> Void in
        if (user != nil) {
            SMKeychainService.saveToken(password)
            var defaults = NSUserDefaults(suiteName: "group.xxx.xxx")
            defaults.setObject(username, forKey: "UsernameKey")
            defaults.synchronize()
            self.delegate?.signedIn!(true)
        } else {
            self.delegate?.signedIn!(false)
        }
    }
}

Has anyone of you tried to load data from parse.com inside of an widget and how did you do it. I can´t even load the data, because like I mentioned the widget crashes at the sign in of the user.
The app itself has no problems with signing in to parse and loading the data.

I solved the problem
I did not implemented Parse.setApplicationId("xxx", clientKey: "xxx"), now I implemented it in viewDidLoad and the code works!

smudis
  • 399
  • 4
  • 13
  • What is the error message? Where exactly does it crash when stepping through he code? – Mundi Oct 17 '14 at 15:26
  • The `NSUserDefaults` are working, the `SMKeychainService` is based on `NSuserDefaults` too. I also tried the method call and the delegate leading back without the Parse code, so it can only be the `PFUser.logInWithUsernameInBackground:` method. – smudis Oct 17 '14 at 16:18

1 Answers1

0

Setting the

        Parse.setApplicationId(appID, clientKey: clientKey)

in the AppDelegate does not work for the extension. Use this code in the viewDidLoad of the extension and it works fine.

ayalcinkaya
  • 3,303
  • 29
  • 25