Problem description
In Xcode 11 beta and iOS 13 beta, versions 1.9.8 and earlier of the iOS SDK cannot upload the deviceToken to the CloudPush server. As a result, push notifications fail. The related code is as follows.
/**
* This is the iOS system method for a successful APNS registration callback. In this method, upload the returned deviceToken to the CloudPush server.
* Note: When testing in a development environment, this method might not be called on the first installation on some devices running iOS 13 or later. This prevents the token from being obtained, and the report fails.
* This is an issue with the Apple system. This issue does not typically occur in a production environment. If this issue occurs during testing:
* 1. Check the device's network connection.
* 2. Delete and reinstall the app to test.
* 3. Disconnect and reconnect the data cable. Then, delete and reinstall the app to test.
* 4. Delete the app, change the bundle ID, and then compile and run. Then, switch back to the original bundle ID, and compile and run to test.
* 5. On the device, go to General settings, shut down the device, and then restart it.
* 6. Check if this method is rewritten elsewhere or if Xinge Push is integrated.
*
* Note: On iOS 9 and later, the deviceToken changes every time you delete and reinstall the app.
* If this method is called but the SDK still cannot get the deviceToken, check if the SDK version is later than 1.9.8.
* */
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"Upload deviceToken to CloudPush server.");
[CloudPushSDK registerDevice:deviceToken withCallback:^(CloudPushCallbackResult *res) {
if (res.success) {
NSLog(@"Register deviceToken success, deviceToken: %@", [CloudPushSDK getApnsDeviceToken]);
} else {
NSLog(@"Register deviceToken failed, error: %@", res.error);
}
}];
}Cause
The data format of the deviceToken has changed. As a result, older SDK versions cannot correctly parse the deviceToken and upload it to the CloudPush server.
Solution
If you perform risky operations, such as modifying instances or data, ensure data security by understanding the disaster recovery and fault tolerance capabilities of your instances.
If you modify the configurations or data of instances, such as ECS and RDS instances, create snapshots or enable features such as RDS log backup beforehand.
If you have granted permissions or submitted security information, such as logon credentials, to the Alibaba Cloud platform, change them promptly.
Upgrade the SDK to version 1.9.9 or later. This version is available on the EMAS console and has been updated in CocoaPods. No changes to your code are required. The updated code in the SDK is as follows.
You can specify the SDK version based on your project requirements. For more information, see Podfile Syntax Reference.
The new SDK version is backward and forward compatible and supports all iOS versions. We recommend that you upgrade to this new version.
# include <arpa/inet.h>
// Transforms the deviceTokenData returned by APNS into a standard deviceToken string.
+ (NSString *)translateDeviceToken:(NSData *)deviceTokenData {
if (deviceTokenData == nil || ![deviceTokenData isKindOfClass:[NSData class]]) {
return nil;
}
const unsigned *tokenBytes = [deviceTokenData bytes];
NSString *deviceTokenStr = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
return deviceTokenStr;
}Applies to
Mobile Push