Skip to content

Commit

Permalink
Merge pull request #5414 from braze-inc/feature/sdk-3289-swift-misc
Browse files Browse the repository at this point in the history
Re-add miscellaneous Swift docs
  • Loading branch information
KellieHawks authored May 12, 2023
2 parents 3b365db + 019d66d commit 49fc23e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 42 deletions.
40 changes: 22 additions & 18 deletions _docs/_developer_guide/platform_integration_guides/sdk_primer.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,24 @@ These properties are collected by the Android SDK upon proper integration.
{: .reset-td-br-1 .reset-td-br-2}

{% endtab %}
{% tab iOS SDK %}
{% tab Swift SDK %}

These properties are collected by the iOS SDK upon proper integration.
These properties are collected by the Swift SDK upon proper integration.

| Name | Description |
|---|---|
| Device Resolution <br> `ABKDeviceOptionResolution`| The screen resolution of the device. The format of this value is "`<width>`x`<height>`". |
| Device Carrier <br> `ABKDeviceOptionCarrier`| The reported mobile carrier. |
| Device Locale <br> `ABKDeviceOptionLocale`| The default locale of the device. |
| Device Model <br> `ABKDeviceOptionModel`| The specific hardware of the device.
| Device OS Version <br> `ABKDeviceOptionOSVersion` | The version of the iOS OS installed on the device. |
| Device IDFV <br> `ABKDeviceOptionIDFV`| Device identifier for vendors. IDFV collection is now optional on our [iOS SDK v5.7.0+](https://www.braze.com/docs/developer_guide/platform_integration_guides/swift/initial_sdk_setup/overview/other_sdk_customizations/swift_idfv/)|
| Device IDFA <br> `ABKDeviceOptionIDFA`| (if supplied) Device identifier for advertisers. |
| Device Push Enabled <br> `ABKDeviceOptionPushEnabled`| Whether this app has push notifications enabled.
| Device Timezone <br> `ABKDeviceOptionTimezone`| The reported time zone of the device.
| Device Push Authorization Status <br> `ABKDeviceOptionPushAuthStatus`| Whether this app has push authorization for the device.
| Device Ad Tracking Enabled <br> `ABKDeviceAdTrackingEnabled`| Whether this app has Ad Tracking enabled. |
| Device Resolution <br> `resolution`| The screen resolution of the device. The format of this value is "`<width>`x`<height>`". |
| Device Carrier <br> `carrier`| The reported mobile carrier. (see note on the [`CTCarrier` deprecation](https://braze-inc.github.io/braze-swift-sdk/documentation/brazekit/braze/configuration-swift.class/deviceproperty/carrier)) |
| Device Locale <br> `locale`| The default locale of the device. |
| Device Model <br> `model`| The specific hardware of the device.
| Device OS Version <br> `osVersion` | The version of the iOS OS installed on the device. |
| Device IDFV <br> `idfv`| Device identifier for vendors. IDFV collection is now optional on our [Swift SDK v5.7.0+](https://www.braze.com/docs/developer_guide/platform_integration_guides/ios/initial_sdk_setup/other_sdk_customizations/swift_idfv/)|
| Device IDFA <br> `idfa`| (if supplied) Device identifier for advertisers. |
| Device Push Enabled <br> `notificationEnabled`| Whether this app has push notifications enabled.
| Device Timezone <br> `timeZone`| The reported time zone of the device.
| Device Push Authorization Status <br> `notificationAuthorizationStatus`| Whether this app has push authorization for the device.
| Device Ad Tracking Enabled <br> `adTrackingEnabled`| Whether this app has Ad Tracking enabled. |
| Device Push Display Options <br> `notificationDisplayOptions`| Display options to match those available in `UNNotificationSettings`. |
{: .reset-td-br-1 .reset-td-br-2}

{% endtab %}
Expand Down Expand Up @@ -136,18 +137,21 @@ An empty allowlist will result in **no** device data being sent to Braze.
{% endalert %}

{% endtab %}
{% tab iOS SDK %}
{% tab Swift SDK %}

You can pass an `appboyOptions` value for `ABKDeviceAllowlistKey` to specify an allowlist for device fields that are collected by the SDK. Fields are defined in `ABKDeviceOptions`. To turn off the collection of all device fields, set the value of this key to `ABKDeviceOptionNone`. Refer to [`Appboy.h`](https://github.com/Appboy/appboy-ios-sdk/blob/master/AppboyKit/include/Appboy.h) for `appboyOptions` key documentation.

To specify allowlisted device fields, assign the bitwise OR of desired fields to `ABKDeviceAllowlistKey` in the `appboyOptions` object passed to `startWithApiKey`.
You can assign a set of eligible fields to [`configuration.devicePropertyAllowList`][4] on your `Braze.Configuration` to specify an allowlist for device fields that are collected by the SDK. The full list of fields is defined in [`Braze.Configuration.DeviceProperty`][5]. To turn off the collection of all device fields, set the value of this property to an empty set (`[]`).

{% alert important %}
By default, all fields are collected by the Braze iOS SDK.
By default, all fields are collected by the Braze Swift SDK. Removing some device properties may disable SDK features.
{% endalert %}

For more usage details, refer to [Storage][6] in the Swift SDK documentation.

{% endtab %}
{% endtabs %}


[3]: {{site.baseurl}}/user_guide/onboarding_with_braze/web_sdk/
[4]: https://braze-inc.github.io/braze-swift-sdk/documentation/brazekit/braze/configuration-swift.class/devicepropertyallowlist
[5]: https://braze-inc.github.io/braze-swift-sdk/documentation/brazekit/braze/configuration-swift.class/deviceproperty
[6]: {{site.baseurl}}/developer_guide/platform_integration_guides/swift/storage
65 changes: 41 additions & 24 deletions _docs/_developer_guide/platform_wide/sdk_authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ This feature is available as of the following [SDK versions]({{ site.baseurl }}/

{% sdk_min_versions swift:5.0.0 android:14.0.0 web:3.3.0 %}

{% alert note %}
For iOS integrations, this page details the steps for the Braze Swift SDK. For sample usage in the legacy AppboyKit iOS SDK, reference [this file](https://github.com/Appboy/appboy-ios-sdk/blob/master/Example/Stopwatch/Sources/AppDelegate.m) and [this file](https://github.com/Appboy/appboy-ios-sdk/blob/master/Example/Stopwatch/Sources/Utils/SdkAuthDelegate.m).
{% endalert %}

### Enable this feature in the Braze SDK.

When this feature is enabled, the Braze SDK will append the current user's last known JWT to network requests made to Braze Servers.
Expand Down Expand Up @@ -119,27 +123,26 @@ Braze.configure(this, brazeConfigBuilder.build())
Alternatively, you can add `<bool name="com_braze_sdk_authentication_enabled">true</bool>` to your braze.xml.
{% endtab %}
{% tab Objective-C %}
To enable SDK Authentication, add the key `EnableSDKAuthentication` to the `Braze` dictionary in your `.plist` file and set it to true.

Alternatively, you can enable SDK Authentication when initializing the SDK:
To enable SDK Authentication, set the `configuration.api.sdkAuthentication` property of your `BRZConfiguration` object to `YES` before initializing the Braze instance:

```objc
[Appboy startWithApiKey:@"YOUR-API-KEY"
inApplication:application
withLaunchOptions:launchOptions
withAppboyOptions:@{ABKEnableSDKAuthenticationKey : @YES}];
BRZConfiguration *configuration =
[[BRZConfiguration alloc] initWithApiKey:@"{BRAZE_API_KEY}"
endpoint:@"{BRAZE_ENDPOINT}"];
configuration.api.sdkAuthentication = YES;
Braze *braze = [[Braze alloc] initWithConfiguration:configuration];
AppDelegate.braze = braze;
```
{% endtab %}
{% tab Swift %}
To enable SDK Authentication, add the key `EnableSDKAuthentication` to the `Braze` dictionary in your `.plist` file and set it to true.
Alternatively, you can enable SDK Authentication when initializing the SDK:
To enable SDK Authentication, set the `configuration.api.sdkAuthentication` property of your `Braze.Configuration` object to `true` when initializing the SDK:
```swift
Appboy.start(withApiKey: "YOUR-API-KEY",
in:application,
withLaunchOptions:launchOptions,
withAppboyOptions:[ ABKEnableSDKAuthenticationKey : true ])
let configuration = Braze.Configuration(apiKey: "{YOUR-BRAZE-API-KEY}",
endpoint: "{YOUR-BRAZE-ENDPOINT}")
configuration.api.sdkAuthentication = true
let braze = Braze(configuration: configuration)
AppDelegate.braze = braze
```
{% endtab %}
{% tab Dart %}
Expand Down Expand Up @@ -207,26 +210,26 @@ Braze.getInstance(this).setSdkAuthenticationSignature("NEW-JWT-TOKEN-FROM-SERVER
Supply the JWT Token when calling [`changeUser`](https://appboy.github.io/appboy-ios-sdk/docs/interface_appboy.html#ac8b369b40e15860b0ec18c0f4b46ac69):

```objc
[[Appboy sharedInstance] changeUser:@"userId" sdkAuthSignature:@"signature"];
[AppDelegate.braze changeUser:@"userId" sdkAuthSignature:@"signature"];
```
Or, when you have refreshed the user's token mid-session:
```objc
[[Appboy sharedInstance] setSdkAuthenticationSignature:@"signature"];
[AppDelegate.braze setSDKAuthenticationSignature:@"signature"];
```
{% endtab %}
{% tab Swift %}

Supply the JWT Token when calling [`changeUser`](https://appboy.github.io/appboy-ios-sdk/docs/interface_appboy.html#ac8b369b40e15860b0ec18c0f4b46ac69):

```swift
Appboy.sharedInstance()?.changeUser("userId", sdkAuthSignature: "signature")
AppDelegate.braze?.changeUser(userId: "userId", sdkAuthSignature: "signature")
```
Or, when you have refreshed the user's token mid-session:

```swift
Appboy.sharedInstance()?.setSdkAuthenticationSignature("signature")
AppDelegate.braze?.set(sdkAuthenticationSignature: "signature")
```
{% endtab %}
{% tab Dart %}
Expand Down Expand Up @@ -293,30 +296,44 @@ Braze.getInstance(this).subscribeToSdkAuthenticationFailures({ error: BrazeSdkAu
```
{% endtab %}
{% tab Objective-C %}

{% alert important %}
Starting in version `5.14.0` of the Braze Swift SDK, the SDK authentication delegate method has been split from the `BrazeDelegate` into a separate `BrazeSDKAuthDelegate`.
{% endalert %}

```objc
[[Appboy sharedInstance] setSdkAuthenticationDelegate:delegate];
Braze *braze = [[Braze alloc] initWithConfiguration:configuration];
braze.sdkAuthDelegate = delegate;
AppDelegate.braze = braze;

// Method to implement in delegate
- (void)handleSdkAuthenticationError:(ABKSdkAuthenticationError *)error {
- (void)braze:(Braze *)braze sdkAuthenticationFailedWithError:(BRZSDKAuthenticationError *)error {
// TODO: Optionally log to your error-reporting service
// TODO: Check if the `user_id` within the `error` matches the currently logged-in user
NSLog(@"Invalid SDK Authentication signature.");
NSString *newSignature = getNewSignatureSomehow(error);
[[Appboy sharedInstance] setSdkAuthenticationSignature:newSignature];
[AppDelegate.braze setSDKAuthenticationSignature:newSignature];
}
```
{% endtab %}
{% tab Swift %}
{% alert important %}
Starting in version `5.14.0` of the Braze Swift SDK, the SDK authentication delegate method has been separated from the `BrazeDelegate` into the `BrazeSDKAuthDelegate` protocol. If you are on a version prior to this, you should implement the SDK authentication delegate method wherever you conform to `BrazeDelegate`.
{% endalert %}
```swift
Appboy.sharedInstance()?.setSdkAuthenticationDelegate(delegate)
let braze = Braze(configuration: configuration)
braze.sdkAuthDelegate = delegate
AppDelegate.braze = braze
// Method to implement in delegate
func handle(_ error: ABKSdkAuthenticationError?) {
func braze(_ braze: Braze, sdkAuthenticationFailedWithError error: Braze.SDKAuthenticationError) {
// TODO: Optionally log to your error-reporting service
// TODO: Check if the `user_id` within the `error` matches the currently logged-in user
print("Invalid SDK Authentication signature.")
let newSignature = getNewSignatureSomehow(error)
Appboy.sharedInstance()?.setSdkAuthenticationSignature(newSignature)
AppDelegate.braze?.set(sdkAuthenticationSignature: newSignature)
}
```
{% endtab %}
Expand Down

0 comments on commit 49fc23e

Please sign in to comment.