Skip to content

Add failure/safety checks for PFInstallation.+currentInstallation. #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ - (BFTask *)getCurrentObjectAsync {
@strongify(self);

__block PFInstallation *installation = task.result;
return [[self.installationIdentifierStore getInstallationIdentifierAsync] continueWithBlock:^id _Nullable(BFTask<NSString *> * _Nonnull task) {
return [[self.installationIdentifierStore getInstallationIdentifierAsync] continueWithSuccessBlock:^id _Nullable(BFTask<NSString *> * _Nonnull task) {
NSString *installationId = task.result.lowercaseString;
if (!installation || ![installationId isEqualToString:installation.installationId]) {
// If there's no installation object, or the object's installation
Expand Down
4 changes: 2 additions & 2 deletions Parse/PFInstallation.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ PF_TV_UNAVAILABLE PF_WATCH_UNAVAILABLE @interface PFInstallation : PFObject<PFSu
If this installation is not stored on disk this method will create a new `PFInstallation`
with `deviceType` and `installationId` fields set to those of the current installation.

@result Returns a `PFInstallation` that represents the currently-running installation.
@result Returns a `PFInstallation` that represents the currently-running installation if it could be loaded from disk, otherwise - `nil`.
*/
+ (instancetype)currentInstallation;
+ (nullable instancetype)currentInstallation;

/**
*Asynchronously* loads the currently-running installation from disk and returns an instance of it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func application(application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
installation?.setDeviceTokenFromData(deviceToken)
installation?.saveInBackground()

PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in
if succeeded {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
installation?.setDeviceTokenFromData(deviceToken)
installation?.saveInBackground()

PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in
if succeeded {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
installation?.setDeviceTokenFromData(deviceToken)
installation?.saveInBackground()

PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in
if succeeded {
Expand Down