GetSocial iOS SDK Manual Initialization Guide¶
Disable Auto Initialization¶
By default GetSocial SDK is initialized automatically on application start. You can disable this behavior and initialize from code.
Using GetSocial Installer Script¶
If you are using GetSocial Installer script, to disable auto initialization:
- In your Xcode project, open Project settings and select target you want to modify.
-
Go to Build Phases tab → Run Script section and add
--auto-init
parameter to GetSocial configuration:./getsocial.sh --app-id="your-getsocial-app-id" --auto-init="false"
Using Info Plist Property¶
If you are not using GetSocial Installer script you have to add .plist
property manually:
- In your Xcode project, open
.plist
file. -
Add property
im.getsocial.sdk.AutoInitSdk
:<key>im.getsocial.sdk.AutoInitSdk</key> <false/>
Initialize From Code¶
To initialize GetSocial SDK from code, just call [GetSocial init]
.
Most of GetSocial APIs require initialized SDK. You can check SDK initialization state in sync or async way.
```objc tab=”Objective-C”
if ([GetSocial isInitialized]) {
// use GetSocial
}
```swift tab="Swift"
if GetSocial.isInitialized() {
// use GetSocial
}
If you want to be notified about initialization complete, you can set a block, that will be invoked when SDK gets initialized or invoked immediately if it is already initialized:
```objc tab=”Objective-C”
[GetSocial executeWhenInitialized:^() {
// GetSocial is ready to be used
}];
```swift tab="Swift"
GetSocial.execute(whenInitialized: {
// GetSocial is ready to be used
})
It can be useful when you want to use GetSocial on application start, but you can not be sure is it ready for using, for example you want to retrieve referral data on application start:
```objc tab=”Objective-C” hl_lines=”9”
@implementation MainViewController
…
- (void)viewDidLoad {
[super viewDidLoad];
…
[GetSocial executeWhenInitialized:^() {
[GetSocial referralDataWithSuccess:… failure:…];
}];
[GetSocial init];
…
}
…
@end
```swift tab="Swift" hl_lines="9"
class ViewController: UIViewController {
...
override func viewDidLoad() {
super.viewDidLoad()
...
GetSocial.execute(whenInitialized: {
GetSocial.referralData(...)
})
GetSocial.initWithAppId(...)
...
}
...
}
...
Initialize With Dynamic Application Id¶
Also, you can specify application ID to initialize with from code:
```objc tab=”Objective-C”
NSString *appId = …;
[GetSocial initWithAppId:appId];
```swift tab="Swift"
let appId = "<APP_ID>"
GetSocial.initWithAppId(appId)