Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix registerCallback
Browse files Browse the repository at this point in the history
ricardopereira committed Feb 14, 2017

Verified

This commit was signed with the committer’s verified signature.
renovate-bot Mend Renovate
1 parent 581e76f commit 08f9d01
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Source/ARTPush.h
Original file line number Diff line number Diff line change
@@ -52,8 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
#ifdef TARGET_OS_IPHONE
/// Register a device, including the information necessary to deliver push notifications to it.
- (void)activate;
- (void)activate:(ARTDeviceDetails *)deviceDetails;
- (void)activate:(ARTDeviceDetails *)deviceDetails registerCallback:(nullable ARTUpdateToken* (^)(ARTDeviceDetails * _Nullable, ARTErrorInfo * _Nullable))registerCallback;
- (void)activateWithRegisterCallback:(void (^)(ARTDeviceDetails * _Nullable, ARTErrorInfo * _Nullable, void (^ _Nullable)(ARTUpdateToken * _Nullable, ARTErrorInfo * _Nullable)))registerCallback;
/// Unregister a device.
- (void)deactivate:(ARTDeviceId *)deviceId;
- (void)deactivate:(ARTDeviceId *)deviceId deregisterCallback:(nullable void (^)(ARTDeviceId * _Nullable, ARTErrorInfo * _Nullable))deregisterCallback;
15 changes: 11 additions & 4 deletions Source/ARTPush.m
Original file line number Diff line number Diff line change
@@ -81,11 +81,11 @@ - (void)activate {
[self activate:self.device registerCallback:nil];
}

- (void)activate:(ARTDeviceDetails *)deviceDetails {
[self activate:deviceDetails registerCallback:nil];
- (void)activateWithRegisterCallback:(void (^)(ARTDeviceDetails *, ARTErrorInfo *, void (^)(ARTUpdateToken *, ARTErrorInfo *)))registerCallback {
[self activate:self.device registerCallback:registerCallback];
}

- (void)activate:(ARTDeviceDetails *)deviceDetails registerCallback:(ARTUpdateToken* (^)(ARTDeviceDetails * _Nullable, ARTErrorInfo * _Nullable))registerCallback {
- (void)activate:(ARTDeviceDetails *)deviceDetails registerCallback:(void (^)(ARTDeviceDetails *, ARTErrorInfo *, void (^)(ARTUpdateToken *, ARTErrorInfo *)))registerCallback {
if (self.state == ARTPushStateActivated) {
return;
}
@@ -100,7 +100,14 @@ - (void)activate:(ARTDeviceDetails *)deviceDetails registerCallback:(ARTUpdateTo
}

if (registerCallback) {
self.device.updateToken = registerCallback(deviceDetails, nil);
registerCallback(deviceDetails, nil, ^(ARTUpdateToken *updateToken, ARTErrorInfo *error) {
if (updateToken) {
self.device.updateToken = updateToken;
}
if (error) {
[_logger error:@"%@: device registration using a `registerCallback` failed (%@)", NSStringFromClass(self.class), error.localizedDescription];
}
});
return;
}

0 comments on commit 08f9d01

Please sign in to comment.