-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1451 from OneSignal/fix/clearing_notifs_when_swip…
…ing_notif_center Fix clearing notifications when the application becomes active instead of when it enters foreground
- Loading branch information
Showing
12 changed files
with
560 additions
and
19 deletions.
There are no files selected for viewing
289 changes: 288 additions & 1 deletion
289
iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Modified MIT License | ||
Copyright 2024 OneSignal | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
1. The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
2. All copies of substantial portions of the Software may only be used in connection | ||
with services provided by OneSignal. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
@interface OSBundleUtils : NSObject | ||
+ (BOOL)isAppUsingUIScene; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Modified MIT License | ||
Copyright 2024 OneSignal | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
1. The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
2. All copies of substantial portions of the Software may only be used in connection | ||
with services provided by OneSignal. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "OSBundleUtils.h" | ||
@implementation OSBundleUtils | ||
|
||
+ (BOOL)isAppUsingUIScene { | ||
if (@available(iOS 13.0, *)) { | ||
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIApplicationSceneManifest"] != nil; | ||
} | ||
return NO; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
Modified MIT License | ||
Copyright 2024 OneSignal | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
1. The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
2. All copies of substantial portions of the Software may only be used in connection | ||
with services provided by OneSignal. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
import XCTest | ||
import OneSignalNotifications | ||
import OneSignalCoreMocks | ||
import UIKit | ||
|
||
final class OneSignalNotificationsTests: XCTestCase { | ||
|
||
var notifTypes: Int32 = 0 | ||
var token: String = "" | ||
|
||
override func setUpWithError() throws { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
self.notifTypes = 0 | ||
self.token = "" | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testClearBadgesWhenAppEntersForeground() throws { | ||
// NotificationManager Start to register lifecycle listener | ||
OSNotificationsManager.start() | ||
// Set badge count > 0 | ||
UIApplication.shared.applicationIconBadgeNumber = 1 | ||
// Then background the app | ||
OneSignalCoreMocks.backgroundApp() | ||
// Foreground the app | ||
OneSignalCoreMocks.foregroundApp() | ||
// Ensure that badge count == 0 | ||
XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) | ||
} | ||
|
||
func testDontclearBadgesWhenAppBecomesActive() throws { | ||
// NotificationManager Start to register lifecycle listener | ||
OSNotificationsManager.start() | ||
// Set badge count > 0 | ||
UIApplication.shared.applicationIconBadgeNumber = 1 | ||
// Then resign active | ||
OneSignalCoreMocks.resignActive() | ||
// App becomes active the app | ||
OneSignalCoreMocks.becomeActive() | ||
// Ensure that badge count == 1 | ||
XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) | ||
} | ||
|
||
func testUpdateNotificationTypesOnAppEntersForeground() throws { | ||
// NotificationManager Start to register lifecycle listener | ||
OSNotificationsManager.start() | ||
|
||
OSNotificationsManager.delegate = self | ||
|
||
XCTAssertEqual(self.notifTypes, 0) | ||
|
||
// Then background the app | ||
OneSignalCoreMocks.backgroundApp() | ||
|
||
// Foreground the app for within 30 seconds | ||
OneSignalCoreMocks.foregroundApp() | ||
|
||
// Ensure that the delegate is updated with the new notification type | ||
XCTAssertEqual(self.notifTypes, ERROR_PUSH_NEVER_PROMPTED) | ||
} | ||
|
||
|
||
} | ||
|
||
extension OneSignalNotificationsTests: OneSignalNotificationsDelegate { | ||
public func setNotificationTypes(_ notificationTypes: Int32) { | ||
self.notifTypes = notificationTypes | ||
} | ||
|
||
public func setPushToken(_ pushToken: String) { | ||
self.token = pushToken | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters