Skip to content

Commit 5ed4ff3

Browse files
authored
Sdk improvements (#350)
* Date Handling • Some users were trying to use the `send_after` field to set delay dates for notifications, and were using NSDate objects to specify the date • NSJSONSerialization cannot automatically convert dates to strings, so this commit adds automatic date conversion for the `postNotification()` method. * Fix Dates Test Issue • The UnitTests target did not have the correct file permission to use the new date conversion NSMutableDictionary category... * Case Insensitive Email Auth Hash Strings • Changes the SDK to always convert email auth hash tokens to be lowercase to prevent issues. * Remove Lowercase Hash Token • It's been decided to perform case insensitive hash token comparisons on the backend instead of performing this conversion on the SDK. • Removed the lowercase string conversion. This also broke some tests in the previous commit which weren't changed to convert the hash token to be lowercase before comparing. * Add Deprecation Notice to syncHashedEmail() • We are deprecating (and will soon remove) the syncHashedEmail() method from the SDK. * PostNotification() Callback Response Thread • Changed the SDK to ensure that PostNotification() callbacks are always called on the main thread to help developers prevent UI bugs * Add Test for Email Subscription State Description • Adds a test to verify that the OSEmailSubscriptionState and OSEmailSubscriptionStateChanges instance description strings are properly formatted * * Fixes two issues that would have crashed the iOS SDK in iOS 7 * Fixes an issue parsing the new notification payload format * Adds a new setting, kOSSettingsKeyPromptBeforeOpeningPushURL. This setting determines what happens when the user taps a push notification containing a launch URL. If the setting = true, the SDK will show a popup asking if the user wants to open the URL. * Fixes an issue with the Swift demo where all tapped notifications would always open the Red view controller (which should only happen in response to tapping a button with id = id1) * Remove Private API • As a convenience, the SDK used to call some deprecated AppDelegate methods (such as application:didReceiveLocalNotification:). • However some developers have raised concerns that this requires the use of private API's • Since this should be relatively rare, we are removing this functionality and will print warnings whenever a developer implements these methods * Fix Web Alert • Fixes the alert so that instead of printing the entire URL address (which could be quite long), it prints only the scheme and the host (ie. http://google.com). • Using localized strings * Cleanup • Fix NSMutableDictionary category copyright • Cleans up unnecessary log statements * Cleanup - Chapter 2 • Remove an unnecessary log statement
1 parent 552c84d commit 5ed4ff3

File tree

15 files changed

+389
-96
lines changed

15 files changed

+389
-96
lines changed

Examples/SwiftExample/OneSignalDemo/AppDelegate.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, OSPermissionObserver, OSS
6161
if let additionalData = result!.notification.payload!.additionalData {
6262
print("additionalData = \(additionalData)")
6363

64-
// DEEP LINK and open url in RedViewController
65-
// Send notification with Additional Data > example key: "OpenURL" example value: "https://google.com"
66-
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
67-
let instantiateRedViewController : RedViewController = mainStoryboard.instantiateViewController(withIdentifier: "RedViewControllerID") as! RedViewController
68-
instantiateRedViewController.receivedURL = additionalData["OpenURL"] as! String!
69-
self.window = UIWindow(frame: UIScreen.main.bounds)
70-
self.window?.rootViewController = instantiateRedViewController
71-
self.window?.makeKeyAndVisible()
72-
7364

7465
if let actionSelected = payload?.actionButtons {
7566
print("actionSelected = \(actionSelected)")

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
CA08FC801FE99B25004C445F /* Requests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA08FC7D1FE99B25004C445F /* Requests.m */; };
133133
CA08FC811FE99B25004C445F /* Requests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA08FC7D1FE99B25004C445F /* Requests.m */; };
134134
CA08FC871FE99BB4004C445F /* OneSignalClientOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = CA08FC831FE99BB4004C445F /* OneSignalClientOverrider.m */; };
135+
CA1873BD2049F7070079CA09 /* NSMutableDictionary+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = CA1873BC2049F7070079CA09 /* NSMutableDictionary+OneSignal.m */; };
136+
CA1873BF2049FB4F0079CA09 /* NSMutableDictionary+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = CA1873BC2049F7070079CA09 /* NSMutableDictionary+OneSignal.m */; };
137+
CA1873C02049FB540079CA09 /* NSMutableDictionary+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = CA1873BC2049F7070079CA09 /* NSMutableDictionary+OneSignal.m */; };
135138
CA63AF8420211F7400E340FB /* EmailTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA63AF8320211F7400E340FB /* EmailTests.m */; };
136139
CA63AF8720211FF800E340FB /* UnitTestCommonMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = CA63AF8620211FF800E340FB /* UnitTestCommonMethods.m */; };
137140
CA63AFC22022670A00E340FB /* ReattemptRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = CA63AFC02022670A00E340FB /* ReattemptRequest.h */; };
@@ -144,6 +147,10 @@
144147
CA810FD1202BA97300A60FED /* OSEmailSubscription.m in Sources */ = {isa = PBXBuildFile; fileRef = CA810FD0202BA97300A60FED /* OSEmailSubscription.m */; };
145148
CA810FD2202BA97600A60FED /* OSEmailSubscription.m in Sources */ = {isa = PBXBuildFile; fileRef = CA810FD0202BA97300A60FED /* OSEmailSubscription.m */; };
146149
CA810FD3202BA97600A60FED /* OSEmailSubscription.m in Sources */ = {isa = PBXBuildFile; fileRef = CA810FD0202BA97300A60FED /* OSEmailSubscription.m */; };
150+
CA97E14E2051C0A5003B8CB8 /* OneSignalWebOpenDialog.h in Headers */ = {isa = PBXBuildFile; fileRef = CA97E14C2051C0A5003B8CB8 /* OneSignalWebOpenDialog.h */; };
151+
CA97E14F2051C0A5003B8CB8 /* OneSignalWebOpenDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = CA97E14D2051C0A5003B8CB8 /* OneSignalWebOpenDialog.m */; };
152+
CA97E1502051C0A5003B8CB8 /* OneSignalWebOpenDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = CA97E14D2051C0A5003B8CB8 /* OneSignalWebOpenDialog.m */; };
153+
CA97E1512051C0A5003B8CB8 /* OneSignalWebOpenDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = CA97E14D2051C0A5003B8CB8 /* OneSignalWebOpenDialog.m */; };
147154
CAEA1C66202BB3C600FBFE9E /* OSEmailSubscription.h in Headers */ = {isa = PBXBuildFile; fileRef = CA810FCF202BA97300A60FED /* OSEmailSubscription.h */; };
148155
/* End PBXBuildFile section */
149156

@@ -267,6 +274,8 @@
267274
CA08FC7D1FE99B25004C445F /* Requests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Requests.m; sourceTree = "<group>"; };
268275
CA08FC821FE99BB4004C445F /* OneSignalClientOverrider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalClientOverrider.h; sourceTree = "<group>"; };
269276
CA08FC831FE99BB4004C445F /* OneSignalClientOverrider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalClientOverrider.m; sourceTree = "<group>"; };
277+
CA1873BB2049F7070079CA09 /* NSMutableDictionary+OneSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableDictionary+OneSignal.h"; sourceTree = "<group>"; };
278+
CA1873BC2049F7070079CA09 /* NSMutableDictionary+OneSignal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableDictionary+OneSignal.m"; sourceTree = "<group>"; };
270279
CA63AF8320211F7400E340FB /* EmailTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EmailTests.m; sourceTree = "<group>"; };
271280
CA63AF8520211FF800E340FB /* UnitTestCommonMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UnitTestCommonMethods.h; sourceTree = "<group>"; };
272281
CA63AF8620211FF800E340FB /* UnitTestCommonMethods.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UnitTestCommonMethods.m; sourceTree = "<group>"; };
@@ -277,6 +286,8 @@
277286
CA70E3382023F24500019273 /* OneSignalCommonDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalCommonDefines.h; sourceTree = "<group>"; };
278287
CA810FCF202BA97300A60FED /* OSEmailSubscription.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSEmailSubscription.h; sourceTree = "<group>"; };
279288
CA810FD0202BA97300A60FED /* OSEmailSubscription.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSEmailSubscription.m; sourceTree = "<group>"; };
289+
CA97E14C2051C0A5003B8CB8 /* OneSignalWebOpenDialog.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalWebOpenDialog.h; sourceTree = "<group>"; };
290+
CA97E14D2051C0A5003B8CB8 /* OneSignalWebOpenDialog.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalWebOpenDialog.m; sourceTree = "<group>"; };
280291
/* End PBXFileReference section */
281292

282293
/* Begin PBXFrameworksBuildPhase section */
@@ -457,6 +468,8 @@
457468
912411F31E73342200E41FD7 /* OneSignalAlertViewDelegate.m */,
458469
912412061E73342200E41FD7 /* OneSignalWebView.h */,
459470
912412071E73342200E41FD7 /* OneSignalWebView.m */,
471+
CA97E14C2051C0A5003B8CB8 /* OneSignalWebOpenDialog.h */,
472+
CA97E14D2051C0A5003B8CB8 /* OneSignalWebOpenDialog.m */,
460473
);
461474
name = UI;
462475
sourceTree = "<group>";
@@ -472,6 +485,8 @@
472485
912412091E73342200E41FD7 /* UIApplicationDelegate+OneSignal.m */,
473486
9124120A1E73342200E41FD7 /* UNUserNotificationCenter+OneSignal.h */,
474487
9124120B1E73342200E41FD7 /* UNUserNotificationCenter+OneSignal.m */,
488+
CA1873BB2049F7070079CA09 /* NSMutableDictionary+OneSignal.h */,
489+
CA1873BC2049F7070079CA09 /* NSMutableDictionary+OneSignal.m */,
475490
);
476491
name = Categories;
477492
sourceTree = "<group>";
@@ -554,6 +569,7 @@
554569
912412391E73342200E41FD7 /* OneSignalWebView.h in Headers */,
555570
91C7725E1E7CCE1000D612D0 /* OneSignalInternal.h in Headers */,
556571
9129C6BD1E89E7AB009CB6A0 /* OSSubscription.h in Headers */,
572+
CA97E14E2051C0A5003B8CB8 /* OneSignalWebOpenDialog.h in Headers */,
557573
);
558574
runOnlyForDeploymentPostprocessing = 0;
559575
};
@@ -705,6 +721,7 @@
705721
9129C6B81E89E59B009CB6A0 /* OSPermission.m in Sources */,
706722
912412121E73342200E41FD7 /* OneSignalAlertViewDelegate.m in Sources */,
707723
912412421E73342200E41FD7 /* UNUserNotificationCenter+OneSignal.m in Sources */,
724+
CA97E14F2051C0A5003B8CB8 /* OneSignalWebOpenDialog.m in Sources */,
708725
9124123A1E73342200E41FD7 /* OneSignalWebView.m in Sources */,
709726
9124123E1E73342200E41FD7 /* UIApplicationDelegate+OneSignal.m in Sources */,
710727
912412261E73342200E41FD7 /* OneSignalMobileProvision.m in Sources */,
@@ -717,6 +734,7 @@
717734
CA810FD1202BA97300A60FED /* OSEmailSubscription.m in Sources */,
718735
CA63AFC32022670A00E340FB /* ReattemptRequest.m in Sources */,
719736
912412221E73342200E41FD7 /* OneSignalLocation.m in Sources */,
737+
CA1873BD2049F7070079CA09 /* NSMutableDictionary+OneSignal.m in Sources */,
720738
1AF75EAE1E8567FD0097B315 /* NSString+OneSignal.m in Sources */,
721739
454F94F51FAD2E5A00D74CCF /* OSNotificationPayload.m in Sources */,
722740
9129C6BE1E89E7AB009CB6A0 /* OSSubscription.m in Sources */,
@@ -741,6 +759,7 @@
741759
91F58D841E7C88220017D24D /* OneSignalNotificationSettingsIOS10.m in Sources */,
742760
9129C6B91E89E59B009CB6A0 /* OSPermission.m in Sources */,
743761
912412131E73342200E41FD7 /* OneSignalAlertViewDelegate.m in Sources */,
762+
CA97E1502051C0A5003B8CB8 /* OneSignalWebOpenDialog.m in Sources */,
744763
0338566B1FBBD2270002F7C1 /* OSNotificationPayload.m in Sources */,
745764
912412431E73342200E41FD7 /* UNUserNotificationCenter+OneSignal.m in Sources */,
746765
9124123B1E73342200E41FD7 /* OneSignalWebView.m in Sources */,
@@ -753,6 +772,7 @@
753772
CA810FD2202BA97600A60FED /* OSEmailSubscription.m in Sources */,
754773
CA63AFC42022670A00E340FB /* ReattemptRequest.m in Sources */,
755774
91F58D8A1E7C9A240017D24D /* OneSignalNotificationSettingsIOS7.m in Sources */,
775+
CA1873BF2049FB4F0079CA09 /* NSMutableDictionary+OneSignal.m in Sources */,
756776
912412231E73342200E41FD7 /* OneSignalLocation.m in Sources */,
757777
1AF75EB01E8569720097B315 /* NSString+OneSignal.m in Sources */,
758778
9129C6BF1E89E7AB009CB6A0 /* OSSubscription.m in Sources */,
@@ -797,6 +817,8 @@
797817
1AF75EAF1E8569710097B315 /* NSString+OneSignal.m in Sources */,
798818
4529DEE71FA82CDC00CEAB1D /* UNUserNotificationCenterOverrider.m in Sources */,
799819
4529DEDB1FA8284E00CEAB1D /* NSDataOverrider.m in Sources */,
820+
CA97E1512051C0A5003B8CB8 /* OneSignalWebOpenDialog.m in Sources */,
821+
CA1873C02049FB540079CA09 /* NSMutableDictionary+OneSignal.m in Sources */,
800822
4529DEF31FA8440A00CEAB1D /* UIAlertViewOverrider.m in Sources */,
801823
4529DEEA1FA8360C00CEAB1D /* UIApplicationOverrider.m in Sources */,
802824
912412281E73342200E41FD7 /* OneSignalMobileProvision.m in Sources */,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2018 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import <Foundation/Foundation.h>
29+
30+
@interface NSMutableDictionary (OneSignal)
31+
- (void)convertDatesToISO8061Strings;
32+
@end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2018 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import "NSMutableDictionary+OneSignal.h"
29+
30+
@implementation NSMutableDictionary (OneSignal)
31+
32+
//NSJSONSerialization will not handle NSDates
33+
//this method converts any occurrences of NSDate into an ISO8061 compliant string
34+
35+
- (void)convertDatesToISO8061Strings {
36+
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
37+
NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
38+
[dateFormatter setLocale:enUSPOSIXLocale];
39+
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
40+
41+
for (NSString *key in self.allKeys) {
42+
id value = self[key];
43+
44+
if ([value isKindOfClass:[NSDate class]])
45+
self[key] = [dateFormatter stringFromDate:(NSDate *)value];
46+
}
47+
}
48+
@end

iOS_SDK/OneSignalSDK/Source/OneSignal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
282282
@end
283283

284284

285+
typedef void (^OSWebOpenURLResultBlock)(BOOL shouldOpen);
285286

286287
typedef void (^OSResultSuccessBlock)(NSDictionary* result);
287288
typedef void (^OSFailureBlock)(NSError* error);
@@ -306,6 +307,9 @@ extern NSString * const kOSSettingsKeyInAppAlerts;
306307
/*Enable In-App display of Launch URLs*/
307308
extern NSString * const kOSSettingsKeyInAppLaunchURL;
308309

310+
/*Prompt user yes/no to open URL's from push notifications*/
311+
extern NSString * const kOSSSettingsKeyPromptBeforeOpeningPushURL;
312+
309313
/* iOS10 +
310314
Set notification's in-focus display option.
311315
Value must be an OSNotificationDisplayType enum
@@ -364,7 +368,7 @@ typedef NS_ENUM(NSUInteger, ONE_S_LOG_LEVEL) {
364368
+ (void)deleteTagsWithJsonString:(NSString*)jsonString;
365369
// Optional method that sends us the user's email as an anonymized hash so that we can better target and personalize notifications sent to that user across their devices.
366370
// Sends as MD5 and SHA1 of the provided email
367-
+ (void)syncHashedEmail:(NSString*)email;
371+
+ (void)syncHashedEmail:(NSString*)email __deprecated_msg("Please refer to our new Email methods/functionality such as setEmail(). This method will be removed in a future version of the OneSignal SDK");
368372

369373
// - Subscription and Permissions
370374
+ (void)IdsAvailable:(OSIdsAvailableBlock)idsAvailableBlock __deprecated_msg("Please use getPermissionSubscriptionState or addSubscriptionObserver and addPermissionObserver instead.");

0 commit comments

Comments
 (0)