Multiple projects behind single application
How to have a single application connected to one of several WonderPush projects
Some customers have the need to maintain separate bases for the audience of a single mobile application or website. For instance a multinational application that starts by asking the customer their country of residence during the user onboarding.
Typical WonderPush SDK integrations are required to provide the Client ID and Client Secret during the earliest boot up time of the mobile applications. In some scenarios, this is still required, and since the WonderPush SDK versions 4.6.0 for Android and 4.4.0 for iOS, it can now try to reuse previously remembered credentials, if available.
Because this requires storing the Client ID and Client Secret in the application storage, this process is opt-in. You application must use a special method to initialize the WonderPush SDK and remember the given credentials for later use. You can also explicitly initialize the WonderPush SDK by asking it to use the remembered credentials.
The classic way of integrating the WonderPush SDK is still recommended for most developers.
Step 1. Upgrade the WonderPush SDK
Make sure to use the WonderPush SDK versions 4.6.0 for Android, and 4.4.0 for iOS, 2.5.0 for Flutter, 3.5.0 for Cordova, 2.5.0 for React Native.
Step 2. Integrate the WonderPush SDK with "remembered credentials"
The first step is to integrate the WonderPush SDK and providing it with the value "USE_REMEMBERED"
for Client ID and Client Secret.
In the very first startup, no remembered credentials will be available, as expected, and you will see a warning in the device logs.
Open all the tabs below matching your setup. Note that for iOS you have to modify both your App Delegate and Notification Service Extension.
android {
defaultConfig {
// Update the following two lines to explicitly ask the WonderPush SDK
// to initialize with the previously remembered credentials, if available.
buildConfigField 'String', 'WONDERPUSH_CLIENT_ID', '"USE_REMEMBERED"'
buildConfigField 'String', 'WONDERPUSH_CLIENT_SECRET', '"USE_REMEMBERED"'
}
}
android {
defaultConfig {
// Update the following two lines to explicitly ask the WonderPush SDK
// to initialize with the previously remembered credentials, if available.
buildConfigField("String", "WONDERPUSH_CLIENT_ID", "\"USE_REMEMBERED\"")
buildConfigField("String", "WONDERPUSH_CLIENT_SECRET", "\"USE_REMEMBERED\"")
}
}
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Update the following call to explicitly ask the WonderPush SDK
// to initialize with the previously remembered credentials, if available.
WonderPush.setClientId("USE_REMEMBERED", secret: "USE_REMEMBERED")
// […]
}
import WonderPushExtension
class NotificationService: WPNotificationServiceExtension {
override class func clientId() -> String {
return "USE_REMEMBERED"
}
override class func clientSecret() -> String {
return "USE_REMEMBERED"
}
}
#import "NotificationService.h"
@implementation NotificationService
+ (NSString *)clientId {
return @"USE_REMEMBERED";
}
+ (NSString *)clientSecret {
return @"USE_REMEMBERED";
}
@end
# Run the following commands to change the plugin variables
# If you were using other variables, do not forget to add them to the second command
cordova plugin rm wonderpush-cordova-sdk --variable CLIENT_ID= --variable CLIENT_SECRET=
cordova plugin add wonderpush-cordova-sdk --variable CLIENT_ID=USE_REMEMBERED --variable CLIENT_SECRET=USE_REMEMBERED
# Alternatively, you should be able to get the same result if you search for and update
# all occurrences of the previously used values and put USE_REMEMBERED instead.
# But be careful as it's easy to miss a place. Do not forget the Notification Service Extension too.
The integration guide gave you the same instructions as the native Android and iOS SDKs.
Just follow the instructions in the "Android" and "iOS" tabs.
# Run the following commands to change the plugin variables
# If you were using other variables, do not forget to add them to the second command
ionic cordova plugin rm wonderpush-cordova-sdk --variable CLIENT_ID= --variable CLIENT_SECRET=
ionic cordova plugin add wonderpush-cordova-sdk --variable CLIENT_ID=USE_REMEMBERED --variable CLIENT_SECRET=USE_REMEMBERED
# Alternatively, you should be able to get the same result if you search for and update
# all occurrences of the previously used values and put USE_REMEMBERED instead.
# But be careful as it's easy to miss a place. Do not forget the Notification Service Extension too.
The integration guide gave you the same instructions as the native Android and iOS SDKs.
Just follow the instructions in the "Android" and "iOS" tabs.
The integration guide gave you the same instructions as the native Android and iOS SDKs.
Just follow the instructions in the "Android" and "iOS" tabs.
Step 3. Once determined, give the credentials to remember
Once the end-user has chosen the country for your application, or whatever necessary onboarding step were necessary for you to determine the correct WonderPush project to use, give the corresponding credentials to the WonderPush SDK so that it can remember them and initialize the SDK.
Context context = this;
WonderPush.initializeAndRememberCredentials(context, "DETERMINED_CLIENT_ID", "DETERMINED_CLIENT_SECRET");
WonderPush.setAndRememberClientId("DETERMINED_CLIENT_ID", secret: "DETERMINED_CLIENT_SECRET")
WonderPush.initializeAndRememberCredentials("DETERMINED_CLIENT_ID", "DETERMINED_CLIENT_SECRET");
WonderPush.initializeAndRememberCredentials("DETERMINED_CLIENT_ID", "DETERMINED_CLIENT_SECRET");
WonderPush.initializeAndRememberCredentials("DETERMINED_CLIENT_ID", "DETERMINED_CLIENT_SECRET");
WonderPush.initializeAndRememberCredentials("DETERMINED_CLIENT_ID", "DETERMINED_CLIENT_SECRET");
Step 4. Ensure calls to the SDK are made after it is initialized
Almost all calls made to the WonderPush SDK prior to it being initialized will be silently rejected with an error message in the device logs, any getter will typically return null
. WonderPush.setUserId()
is a notable exception, but any call to track events or change tags or custom properties will not be honored.
Make sure that you do not call other methods of the WonderPush SDK prior to having given it credentials to remember and having initialized it.
Uninstall and reinstall your application and take the onboarding again. If you see any message complaining the WonderPush SDK is not initialized in the device logs due to a call you made, you will need to postpone it.
For users of frameworks, make sure to look at the native device logs, not just the logs captured by your framework's favorite logging method. For Android, run your application using Android Studio or look at logcat directly. For iOS, run your application using Xcode.
Updated 4 days ago