Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7bba8d

Browse files
committed
+ added deprecation to stripMobilePayload
+ added 'stripMobilePayload' deprecation information output to Xcode console [#139015913] [ci skip]
1 parent 3450600 commit f7bba8d

3 files changed

Lines changed: 63 additions & 3 deletions

File tree

Example/PubNub Example.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@
619619
GCC_WARN_SIGN_COMPARE = YES;
620620
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
621621
INFOPLIST_FILE = "PubNub/PubNub Example-Info.plist";
622-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
622+
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
623623
MODULE_NAME = ExampleApp;
624624
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
625625
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -651,7 +651,7 @@
651651
GCC_WARN_SIGN_COMPARE = YES;
652652
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
653653
INFOPLIST_FILE = "PubNub/PubNub Example-Info.plist";
654-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
654+
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
655655
MODULE_NAME = ExampleApp;
656656
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
657657
PRODUCT_NAME = "$(TARGET_NAME)";

PubNub/Core/PubNub+Core.m

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ - (void)setupClientLogger;
165165
*/
166166
- (void)printLogVerbosityInformation;
167167

168+
/**
169+
@brief Check client configuration and notify about outdated API and options.
170+
171+
@since 4.5.13
172+
*/
173+
- (void)notifyDeprecatedAPI;
174+
168175
#pragma mark -
169176

170177

@@ -235,6 +242,7 @@ - (instancetype)initWithConfiguration:(PNConfiguration *)configuration
235242
_instanceID = [@"58EB05C9-9DE4-4118-B5D7-EE059FBF19A9" copy];
236243
}
237244
[self prepareNetworkManagers];
245+
[self notifyDeprecatedAPI];
238246

239247
_subscriberManager = [PNSubscriber subscriberForClient:self];
240248
_sequenceManager = [PNPublishSequence sequenceForClient:self];
@@ -601,6 +609,57 @@ - (void)printLogVerbosityInformation {
601609
[enabledFlags componentsJoinedByString:@", "]);
602610
}
603611

612+
- (void)notifyDeprecatedAPI {
613+
614+
NSMutableString *deprecation = [NSMutableString new];
615+
[deprecation appendString:@"\n\n\n--------------------------------------------\n- PubNub deprecated API "
616+
"usage notification -\n--------------------------------------------\n\n"];
617+
if (self.configuration.shouldStripMobilePayload) {
618+
619+
[deprecation appendString:@"- Deprecated: PNConfiguration.shouldStripMobilePayload property.-\n"
620+
"When set to YES SDK automatically stripped out original message\nfrompayload which combined message"
621+
" and push notification payloads.\n\nThis deprecation may affect application in case if it "
622+
"used\npublish API to send messages along with push notification payloads.\nProperty completely will"
623+
" be deprecated with next 'major' SDK update.\n\n"];
624+
625+
[deprecation appendString:@"If application's code rely on automatic messages clean up (send\nmobile "
626+
"push notifications along with messages or store message\ninside payload) it is suggested to update "
627+
"this code before property\nwill be completely removed from SDK.\nAt first "
628+
"`shouldStripMobilePayload` should be set to NO (YES by\ndefault). Next will be update callback "
629+
"which handle new messages:\n\n"
630+
"\t- (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {\n\n"
631+
"\t\tid messageData = message.data.message;\n"
632+
"\t\tif ([messageData isKindOfClass:[NSDictionary class]]) {\n\n"
633+
"\t\t\t// It will be better to access cipher key directly, because 'currentConfiguration'\n"
634+
"\t\t\t// make copy of PNConfiguration each time.\n"
635+
"\t\t\tNSString *cipherKey = [client currentConfiguration].cipherKey;\n"
636+
"\t\t\tNSMutableDictionary *messagePayload = [messageData mutableCopy];\n"
637+
"\t\t\tif (cipherKey.length && messagePayload[@\"pn_other\"]) {\n\n"
638+
"\t\t\t\tNSError *parseError = nil;\n"
639+
"\t\t\t\tid decryptedMessageData = [PNAES decrypt:messagePayload[@\"pn_other\"] withKey:cipherKey \n"
640+
"\t\t\t\t andError:&parseError];\n"
641+
"\t\t\t\tif (decryptedMessageData) {\n\n"
642+
"\t\t\t\t\tmessageData = [NSJSONSerialization JSONObjectWithData:decryptedMessageData\n"
643+
"\t\t\t\t\t options:NSJSONReadingAllowFragments\n"
644+
"\t\t\t\t\t error:&parseError];\n"
645+
"\t\t\t\t}\n"
646+
"\t\t\t\tif (!parseError) {\n\n"
647+
"\t\t\t\t\tif (![messageData isKindOfClass:[NSDictionary class]]) {\n\n"
648+
"\t\t\t\t\t\tmessagePayload[@\"pn_other\"] = messageData;\n"
649+
"\t\t\t\t\t} else { [messagePayload addEntriesFromDictionary:messageData]; }\n"
650+
"\t\t\t\t}\n"
651+
"\t\t\t\telse { /* Handle message decryption and JSON decode. */ }\n"
652+
"\t\t\t}\n"
653+
"\t\t\t// Remove keys for any used push notification provider.\n"
654+
"\t\t\t[messagePayload removeObjectsForKeys:@[@\"pn_apns\", @\"pn_gcm\", @\"pn_mpns\"]];\n"
655+
"\t\t\tmessageData = (messagePayload[@\"pn_other\"]?: messagePayload);\n"
656+
"\t\t}\n"
657+
"\t\tNSLog(@\"Received message: %@\", messageData);\n"
658+
"\t}\n\n\n"];
659+
NSLog(@"%@", deprecation);
660+
}
661+
}
662+
604663
- (void)dealloc {
605664

606665
#if TARGET_OS_IOS

PubNub/Data/PNConfiguration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ NS_ASSUME_NONNULL_BEGIN
275275
276276
@since 4.5.0
277277
*/
278-
@property (nonatomic, assign, getter = shouldStripMobilePayload) BOOL stripMobilePayload NS_SWIFT_NAME(stripMobilePayload);
278+
@property (nonatomic, assign, getter = shouldStripMobilePayload) BOOL stripMobilePayload NS_SWIFT_NAME(stripMobilePayload)
279+
DEPRECATED_MSG_ATTRIBUTE("This option deprecated and will be removed in next general SDK update.");
279280

280281
/**
281282
@brief Construct configuration instance using minimal required data.

0 commit comments

Comments
 (0)