Browse Source

Fixed push notifications device token parsing on iOS and macOS

tags/2021-05-28
ed 5 years ago
parent
commit
3f111dbf83
2 changed files with 30 additions and 10 deletions
  1. +15
    -5
      modules/juce_gui_extra/native/juce_ios_PushNotifications.cpp
  2. +15
    -5
      modules/juce_gui_extra/native/juce_mac_PushNotifications.cpp

+ 15
- 5
modules/juce_gui_extra/native/juce_ios_PushNotifications.cpp View File

@@ -841,12 +841,22 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
void registeredForRemoteNotifications (NSData* deviceTokenToUse) override
{
NSString* deviceTokenString = [[[[deviceTokenToUse description]
stringByReplacingOccurrencesOfString: nsStringLiteral ("<") withString: nsStringLiteral ("")]
stringByReplacingOccurrencesOfString: nsStringLiteral (">") withString: nsStringLiteral ("")]
stringByReplacingOccurrencesOfString: nsStringLiteral (" ") withString: nsStringLiteral ("")];
deviceToken = [deviceTokenToUse]() -> String
{
auto length = deviceTokenToUse.length;
if (auto* buffer = (const unsigned char*) deviceTokenToUse.bytes)
{
NSMutableString* hexString = [NSMutableString stringWithCapacity: (length * 2)];
for (int i = 0; i < length; ++i)
[hexString appendFormat:@"%02x", buffer[i]];
deviceToken = nsStringToJuce (deviceTokenString);
return nsStringToJuce ([hexString copy]);
}
return {};
}();
initialised = true;


+ 15
- 5
modules/juce_gui_extra/native/juce_mac_PushNotifications.cpp View File

@@ -469,12 +469,22 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
//PushNotificationsDelegate
void registeredForRemoteNotifications (NSData* deviceTokenToUse) override
{
auto deviceTokenString = [[[[deviceTokenToUse description]
stringByReplacingOccurrencesOfString: nsStringLiteral ("<") withString: nsStringLiteral ("")]
stringByReplacingOccurrencesOfString: nsStringLiteral (">") withString: nsStringLiteral ("")]
stringByReplacingOccurrencesOfString: nsStringLiteral (" ") withString: nsStringLiteral ("")];
deviceToken = [deviceTokenToUse]() -> String
{
auto length = deviceTokenToUse.length;
if (auto* buffer = (const unsigned char*) deviceTokenToUse.bytes)
{
NSMutableString* hexString = [NSMutableString stringWithCapacity: (length * 2)];
for (int i = 0; i < length; ++i)
[hexString appendFormat:@"%02x", buffer[i]];
deviceToken = nsStringToJuce (deviceTokenString);
return nsStringToJuce ([hexString copy]);
}
return {};
}();
initialised = true;


Loading…
Cancel
Save