Skip to content

Commit 6ceb44c

Browse files
committed
Update MIGRATION_GUIDE.md
1 parent 664c1cd commit 6ceb44c

File tree

1 file changed

+47
-52
lines changed

1 file changed

+47
-52
lines changed

MIGRATION_GUIDE.md

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,15 @@ The current device’s push subscription can be retrieved via:
143143

144144
**Objective-C**
145145
```objc
146-
id<OSPushSubscription> pushSubscription = OneSignal.User.pushSubscription;
146+
OneSignal.User.pushSubscription.id;
147+
OneSignal.User.pushSubscription.token;
148+
OneSignal.User.pushSubscription.optedIn;
147149
```
148150
**Swift**
149151
```swift
150-
let pushSubscription: OSPushSubscription = OneSignal.User.pushSubscription
152+
OneSignal.User.pushSubscription.id
153+
OneSignal.User.pushSubscription.token
154+
OneSignal.User.pushSubscription.optedIn
151155
```
152156

153157
### **Opting In and Out of Push Notifications**
@@ -186,25 +190,25 @@ Email and/or SMS subscriptions can be added or removed via the following methods
186190
// Add email subscription
187191
[OneSignal.User addEmail:@"[email protected]"];
188192
// Remove previously added email subscription
189-
BOOL success = [OneSignal.User removeEmail:@"[email protected]"];
193+
[OneSignal.User removeEmail:@"[email protected]"];
190194
191195
// Add SMS subscription
192-
[OneSignal.User addSmsNumber:@"+15558675309"];
196+
[OneSignal.User addSms:@"+15558675309"];
193197
// Remove previously added SMS subscription
194-
BOOL succss = [OneSignal.User removeSmsNumber:@"+15558675309"];
198+
[OneSignal.User removeSms:@"+15558675309"];
195199
```
196200

197201
**Swift**
198202
```swift
199203
// Add email subscription
200204
OneSignal.User.addEmail("[email protected]")
201205
// Remove previously added email subscription
202-
let success: Bool = OneSignal.User.removeEmail("[email protected]")
206+
OneSignal.User.removeEmail("[email protected]")
203207

204208
// Add SMS subscription
205-
OneSignal.User.addSmsNumber("+15558675309")
209+
OneSignal.User.addSms("+15558675309")
206210
// Remove previously added SMS subscription
207-
let success: Bool = OneSignal.User.removeSmsNumber("+15558675309")
211+
OneSignal.User.removeSms("+15558675309")
208212
```
209213

210214
# API Reference
@@ -291,15 +295,15 @@ The User name space is accessible via `OneSignal.User` and provides access to us
291295
| **Swift** | **Objective-C** | **Description** |
292296
| --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
293297
| `OneSignal.User.setLanguage("en")` | `[OneSignal.User setLanguage:@"en"]` | *Set the 2-character language for this user.* |
294-
| `let pushSubscription: OSPushSubscription = OneSignal.User.pushSubscription` | `id<OSPushSubscription> pushSubscription = OneSignal.User.pushSubscription` | *The push subscription associated to the current user.* |
298+
| `let pushSubscriptionProperty = OneSignal.User.pushSubscription.<PROPERTY>` | `id pushSubscriptionProperty = OneSignal.User.pushSubscription.<PROPERTY>` | *The push subscription associated to the current user.* |
295299
| `OneSignal.User.addAlias(label: "ALIAS_LABEL", id: "ALIAS_ID")` | `[OneSignal.User addAliasWithLabel:@"ALIAS_LABEL" id:@"ALIAS_ID"]` | *Set an alias for the current user. If this alias label already exists on this user, it will be overwritten with the new alias id.* |
296300
| `OneSignal.User.addAliases(["ALIAS_LABEL_01": "ALIAS_ID_01", "ALIAS_LABEL_02": "ALIAS_ID_02"])` | `[OneSignal.User addAliases:@{@"ALIAS_LABEL_01": @"ALIAS_ID_01", @"ALIAS_LABEL_02": @"ALIAS_ID_02"}]` | *Set aliases for the current user. If any alias already exists, it will be overwritten to the new values.* |
297301
| `OneSignal.User.removeAlias("ALIAS_LABEL")` | `[OneSignal.User removeAlias:@"ALIAS_LABEL"]` | *Remove an alias from the current user.* |
298302
| `OneSignal.User.removeAliases(["ALIAS_LABEL_01", "ALIAS_LABEL_02"])` | `[OneSignal.User removeAliases:@[@"ALIAS_LABEL_01", @"ALIAS_LABEL_02"]]` | *Remove aliases from the current user.* |
299303
| `OneSignal.User.addEmail("[email protected]")` | `[OneSignal.User addEmail:@"[email protected]"]` | *Add a new email subscription to the current user.* |
300-
| `let success: Bool = OneSignal.User.removeEmail("[email protected]")` | `BOOL success = [OneSignal.User removeEmail:@"[email protected]"]` | *Remove an email subscription from the current user. Returns `false` if the specified email does not exist on the user within the SDK, and no request will be made.* |
301-
| `OneSignal.User.addSmsNumber("+15558675309")` | `[OneSignal.User addSmsNumber:@"+15558675309"]` | *Add a new SMS subscription to the current user.* |
302-
| `let success: Bool = OneSignal.User.removeSmsNumber("+15558675309")` | `BOOL success = [OneSignal.User removeSmsNumber:@"+15558675309"]` | *Remove an SMS subscription from the current user. Returns `false` if the specified SMS number does not exist on the user within the SDK, and no request will be made.* |
304+
| `OneSignal.User.removeEmail("[email protected]")` | `[OneSignal.User removeEmail:@"[email protected]"]` | *Remove an email subscription from the current user. Returns `false` if the specified email does not exist on the user within the SDK, and no request will be made.* |
305+
| `OneSignal.User.addSms("+15558675309")` | `[OneSignal.User addSms:@"+15558675309"]` | *Add a new SMS subscription to the current user.* |
306+
| `OneSignal.User.removeSms("+15558675309")` | `[OneSignal.User removeSms:@"+15558675309"]` | *Remove an SMS subscription from the current user. Returns `false` if the specified SMS number does not exist on the user within the SDK, and no request will be made.* |
303307
| `OneSignal.User.addTag(key: "KEY", value: "VALUE")` | `[OneSignal.User addTagWithKey:@"KEY" value:@"VALUE"]` | *Add a tag for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. If the tag key already exists, it will be replaced with the value provided here.* |
304308
| `OneSignal.User.addTags(["KEY_01": "VALUE_01", "KEY_02": "VALUE_02"])` | `[OneSignal.User addTags:@{@"KEY_01": @"VALUE_01", @"KEY_02": @"VALUE_02"}]` | *Add multiple tags for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. If the tag key already exists, it will be replaced with the value provided here.* |
305309
| `OneSignal.User.removeTag("KEY")` | `[OneSignal.User removeTag:@"KEY"]` | *Remove the data tag with the provided key from the current user.* |
@@ -319,7 +323,7 @@ The Push Subscription name space is accessible via `OneSignal.User.pushSubscript
319323
| `let optedIn: Bool = OneSignal.User.pushSubscription.optedIn` | `BOOL optedIn = OneSignal.User.pushSubscription.optedIn` | *Gets a boolean value indicating whether the current user is opted in to push notifications. This returns `true` when the app has notifications permission and `optedOut` is called. ***Note:*** Does not take into account the existence of the subscription ID and push token. This boolean may return `true` but push notifications may still not be received by the user.* |
320324
| `OneSignal.User.pushSubscription.optIn()` | `[OneSignal.User.pushSubscription optIn]` | *Call this method to receive push notifications on the device or to resume receiving of push notifications after calling `optOut`. If needed, this method will prompt the user for push notifications permission.* |
321325
| `OneSignal.User.pushSubscription.optOut()` | `[OneSignal.User.pushSubscription optOut]` | *If at any point you want the user to stop receiving push notifications on the current device (regardless of system-level permission status), you can call this method to opt out.* |
322-
| `addObserver(_ observer: OSPushSubscriptionObserver) → OSPushSubscriptionState?`<br><br>***See below for usage*** | `(OSPushSubscriptionState * _Nullable)addObserver:(id <OSPushSubscriptionObserver> _Nonnull)observer`<br><br>***See below for usage*** | *The `OSPushSubscriptionObserver.onOSPushSubscriptionChanged` method will be fired on the passed-in object when the push subscription changes. This method returns the current `OSPushSubscriptionState` at the time of adding this observer.* |
326+
| `addObserver(_ observer: OSPushSubscriptionObserver)`<br><br>***See below for usage*** | `(void)addObserver:(id <OSPushSubscriptionObserver> _Nonnull)observer`<br><br>***See below for usage*** | *The `OSPushSubscriptionObserver.onOSPushSubscriptionChanged` method will be fired on the passed-in object when the push subscription changes. This method returns the current `OSPushSubscriptionState` at the time of adding this observer.* |
323327
| `removeObserver(_ observer: OSPushSubscriptionObserver)`<br><br>***See below for usage*** | `(void)removeObserver:(id <OSPushSubscriptionObserver> _Nonnull)observer`<br><br>***See below for usage*** | *Remove a push subscription observer that has been previously added.* |
324328

325329
### Push Subscription Observer
@@ -338,7 +342,7 @@ Any object implementing the `OSPushSubscriptionObserver` protocol can be added a
338342
339343
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
340344
// Add your AppDelegate as an observer
341-
OSPushSubscriptionState* state = [OneSignal.User.pushSubscription addObserver:self];
345+
[OneSignal.User.pushSubscription addObserver:self];
342346
}
343347

344348
// Add this new method
@@ -359,7 +363,7 @@ Any object implementing the `OSPushSubscriptionObserver` protocol can be added a
359363
360364
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
361365
// Add your AppDelegate as an observer, and the current OSPushSubscriptionState will be returned
362-
let state: OSPushSubscriptionState? = OneSignal.User.pushSubscription.addObserver(self as OSPushSubscriptionObserver)
366+
OneSignal.User.pushSubscription.addObserver(self as OSPushSubscriptionObserver)
363367
print("Current pushSubscriptionState: \n\(state)")
364368
}
365369
@@ -464,26 +468,22 @@ Any object implementing the `OSPermissionObserver` protocol can be added as an o
464468
}
465469

466470
// Add this new method
467-
- (void)onOSPermissionChanged:(OSPermissionStateChanges*)stateChanges {
468-
// Example of detecting anwsering the permission prompt
469-
if (stateChanges.from.status == OSNotificationPermissionNotDetermined) {
470-
if (stateChanges.to.status == OSNotificationPermissionAuthorized)
471-
NSLog(@"Thanks for accepting notifications!");
472-
else if (stateChanges.to.status == OSNotificationPermissionDenied)
473-
NSLog(@"Notifications not accepted. You can turn them on later under your iOS settings.");
471+
- (void)onOSPermissionChanged:(OSPermissionState*)state {
472+
// Example of detecting the curret permission
473+
if (state.permission == true) {
474+
NSLog(@"Device has permission to display notifications");
475+
} else {
476+
NSLog(@"Device does not have permission to display notifications");
474477
}
475478
// prints out all properties
476-
NSLog(@"PermissionStateChanges:\n%@", stateChanges);
479+
NSLog(@"PermissionState:\n%@", state);
477480
}
478481

479482
// Output:
480483
/*
481-
Thanks for accepting notifications!
482-
PermissionStateChanges:
483-
<OSPermissionStateChanges:
484-
from: <OSPermissionState: hasPrompted: 1, status: NotDetermined, provisional: 0>,
485-
to: <OSPermissionState: hasPrompted: 1, status: Authorized, provisional: 0>
486-
>
484+
Device has permission to display notifications
485+
PermissionState:
486+
<OSPermissionState: permission: 1>
487487
*/
488488

489489
@end
@@ -498,33 +498,28 @@ Any object implementing the `OSPermissionObserver` protocol can be added as an o
498498
class AppDelegate: UIResponder, UIApplicationDelegate, OSPermissionObserver {
499499
500500
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
501-
// Add your AppDelegate as an observer
502-
OneSignal.Notifications.addPermissionObserver(self as OSPermissionObserver)
503-
}
504-
505-
// Add this new method
506-
func onOSPermissionChanged(_ stateChanges: OSPermissionStateChanges) {
507-
// Example of detecting answering the permission prompt
508-
if stateChanges.from.status == OSNotificationPermission.notDetermined {
509-
if stateChanges.to.status == OSNotificationPermission.authorized {
510-
print("Thanks for accepting notifications!")
511-
} else if stateChanges.to.status == OSNotificationPermission.denied {
512-
print("Notifications not accepted. You can turn them on later under your iOS settings.")
513-
}
501+
// Add your AppDelegate as an observer
502+
OneSignal.Notifications.addPermissionObserver(self as OSPermissionObserver)
503+
}
504+
505+
// Add this new method
506+
func onOSPermissionChanged(_ state: OSPermissionState) {
507+
// Example of detecting the curret permission
508+
if state.permission == true {
509+
print("Device has permission to display notifications")
510+
} else {
511+
print("Device does not have permission to display notifications")
512+
}
513+
// prints out all properties
514+
print("PermissionState: \n\(state)")
514515
}
515-
// prints out all properties
516-
print("PermissionStateChanges: \n\(stateChanges)")
517-
}
518516
}
519517
520518
// Output:
521519
/*
522-
Thanks for accepting notifications!
523-
PermissionStateChanges:
524-
<OSPermissionStateChanges:
525-
from: <OSPermissionState: hasPrompted: 1, status: NotDetermined, provisional: 0>,
526-
to: <OSPermissionState: hasPrompted: 1, status: Authorized, provisional: 0>
527-
>
520+
Device has permission to display notifications
521+
PermissionState:
522+
<OSPermissionState: permission: 1>
528523
*/
529524
530525
// Remove the observer
@@ -722,7 +717,7 @@ The Debug namespace is accessible via `OneSignal.Debug` and provide access to de
722717
| **Swift** | **Objective-C** | **Description** |
723718
| ------------------------------------------ | ------------------------------------------------ | ---------------------------------------------------------------------------------- |
724719
| `OneSignal.Debug.setLogLevel(.LL_VERBOSE)` | `[OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE]` | *Sets the log level the OneSignal SDK should be writing to the Xcode log.* |
725-
| `OneSignal.Debug.setVisualLevel(.LL_NONE)` | `[OneSignal.Debug setVisualLevel:ONE_S_LL_NONE]` | *Sets the logging level to show as alert dialogs.* |
720+
| `OneSignal.Debug.setAlertLevel(.LL_NONE)` | `[OneSignal.Debug setAlertLevel:ONE_S_LL_NONE]` | *Sets the logging level to show as alert dialogs.* |
726721

727722

728723
# Glossary

0 commit comments

Comments
 (0)