Skip to content

Commit

Permalink
Merge pull request #689 from meganz/hotfix/register_push_notification
Browse files Browse the repository at this point in the history
Allow register push notification token with type 3 (iOS standard push…
  • Loading branch information
javiserrano authored Jun 20, 2017
2 parents 82c9657 + 1779cd6 commit 3a2bc39
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions bindings/ios/MEGASdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ typedef NS_ENUM(NSInteger, HTTPServer) {
HTTPServerAllowLastLocalLink = 2
};

typedef NS_ENUM(NSUInteger, PushNotificationTokenType) {
PushNotificationTokenTypeAndroid = 1,
PushNotificationTokenTypeiOSVoIP = 2,
PushNotificationTokenTypeiOSStandard = 3
};

/**
* @brief Allows to control a MEGA account or a public folder.
*
Expand Down
4 changes: 2 additions & 2 deletions bindings/ios/MEGASdk.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1434,12 +1434,12 @@ - (NSInteger)httpServerGetMaxOutputSize {
}

- (void)registeriOSdeviceToken:(NSString *)deviceToken delegate:(id<MEGARequestDelegate>)delegate {
self.megaApi->registerPushNotifications(2, deviceToken ? [deviceToken UTF8String] : NULL, [self createDelegateMEGARequestListener:delegate singleListener:YES]);
self.megaApi->registerPushNotifications(PushNotificationTokenTypeiOSStandard, deviceToken ? [deviceToken UTF8String] : NULL, [self createDelegateMEGARequestListener:delegate singleListener:YES]);

}

- (void)registeriOSdeviceToken:(NSString *)deviceToken {
self.megaApi->registerPushNotifications(2, deviceToken ? [deviceToken UTF8String] : NULL);
self.megaApi->registerPushNotifications(PushNotificationTokenTypeiOSStandard, deviceToken ? [deviceToken UTF8String] : NULL);
}

#endif
Expand Down
14 changes: 13 additions & 1 deletion include/megaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4419,6 +4419,12 @@ class MegaApi
TRANSFER_METHOD_AUTO_ALTERNATIVE = 4
};

enum {
PUSH_NOTIFICATION_ANDROID = 1,
PUSH_NOTIFICATION_IOS_VOIP = 2,
PUSH_NOTIFICATION_IOS_STD = 3
};

/**
* @brief Constructor suitable for most applications
* @param appKey AppKey of your application
Expand Down Expand Up @@ -9640,12 +9646,18 @@ class MegaApi
* This function attach a token to the current session, which is intended to get push notifications
* on mobile platforms like Android and iOS.
*
* The push notification mechanism is platform-dependent. Hence, the app should indicate the
* type of push notification to be registered. Currently, the different types are:
* - MegaApi::PUSH_NOTIFICATION_ANDROID = 1
* - MegaApi::PUSH_NOTIFICATION_IOS_VOIP = 2
* - MegaApi::PUSH_NOTIFICATION_IOS_STD = 3
*
* The associated request type with this request is MegaRequest::TYPE_REGISTER_PUSH_NOTIFICATION
* Valid data in the MegaRequest object received on callbacks:
* - MegaRequest::getText - Returns the token provided.
* - MegaRequest::getNumber - Returns the device type provided.
*
* @param deviceType Integer id for the provider. 1 for Android, 2 for iOS
* @param deviceType Type of notification to be registered.
* @param token Character array representing the token to be registered.
* @param listener MegaRequestListener to track this request
*/
Expand Down
5 changes: 4 additions & 1 deletion src/megaapi_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14635,7 +14635,10 @@ void MegaApiImpl::sendPendingRequests()
int deviceType = request->getNumber();
const char *token = request->getText();

if ((deviceType != 1 && deviceType != 2) || token == NULL)
if ((deviceType != MegaApi::PUSH_NOTIFICATION_ANDROID &&
deviceType != MegaApi::PUSH_NOTIFICATION_IOS_VOIP &&
deviceType != MegaApi::PUSH_NOTIFICATION_IOS_STD)
|| token == NULL)
{
e = API_EARGS;
break;
Expand Down

0 comments on commit 3a2bc39

Please sign in to comment.