Code Examples
Import Groundsage SDK
Swift
import GroundSageSDK
Objective-c
@import GroundSageSDK;
Setting up api key or secret
Swift
// set your api key and api secret. You do this step through add *IAGSApiKey* and *IAGSSecretKey* to application plist
IAGSManager.shared.setApiKey("SET YOUR API KEY HERE", andSecret: "SET YOUR SECRET KEY HERE")
Objective-c
// set your api key and api secret. You do this step through add *IAGSApiKey* and *IAGSSecretKey* to application plist
[[IAGSManager sharedManager] setApiKey:@"SET YOUR API KEY HERE" andSecret:@"SET YOUR SECRET KEY HERE"];
Alternative, you can add api key
IAGSApiKey
and api secretIAGSSecretKey
to your application plist.
Request venue information
Swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, IAGSManagerDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// set your api key and api secret. You do this step through add *IAGSApiKey* and *IAGSSecretKey* to application plist
IAGSManager.shared.setApiKey("SET YOUR API KEY HERE", andSecret: "SET YOUR SECRET KEY HERE")
// start to request Venue information
IAGSManager.shared.requestVenueInfo { (venues, error) in
print("venues=\(venues), error=\(error)")
}
return true
}
}
Objective-c
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// set your api key and api secret. You do this step through add *IAGSApiKey* and *IAGSSecretKey* to application plist
[[IAGSManager sharedManager] setApiKey:@"SET YOUR API KEY HERE" andSecret:@"SET YOUR SECRET KEY HERE"];
// start to request Venue information
[[IAGSManager sharedManager] requestVenueInfoWithCompletionHandler:^(NSArray<IAGSVenue *> * _Nullable venues, NSError * _Nullable error) {
// NSLog(@"%@, %@", venues, error);
}];
return YES;
}
@end
Register a callback and subscription
Swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, IAGSManagerDelegate {
func didUpdate(manager: IAGSManager, venueDensity: IAGSVenueDensity) {
print("density : \(venueDensity)")
}
func didEnterDensityRegion(_ manager: IAGSManager, region: IARegion) {
print("Enter region : \(region)")
}
func didExitDensityRegion(_ manager: IAGSManager, region: IARegion) {
print("Exit region : \(region)")
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// set your api key and api secret. You do this step through add *IAGSApiKey* and *IAGSSecretKey* to application plist
IAGSManager.shared.setApiKey("SET YOUR API KEY HERE", andSecret: "SET YOUR SECRET KEY HERE")
// register delegate for subscription callback
IAGSManager.shared.addGroundSageDelegate(self)
// start subscription
IAGSManager.shared.startSubscription()
return true
}
}
Objective-c
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// set your api key and api secret. You do this step through add *IAGSApiKey* and *IAGSSecretKey* to application plist
[[IAGSManager sharedManager] setApiKey:@"SET YOUR API KEY HERE" andSecret:@"SET YOUR SECRET KEY HERE"];
// register delegate for subscription callback
[[IAGSManager sharedManager] addGroundSageDelegate:self];
// start subscription
[[IAGSManager sharedManager] startSubscription];
return YES;
}
#pragma mark - IAGSManager delegate
- (void)didUpdate:(IAGSManager *)manager venueDensity:(IAGSVenueDensity *)venueDensity {
NSLog(@"venueDensity = %@", venueDensity);
}
- (void)didEnterDensityRegion:(IAGSManager *)manager region:(IARegion *)region {
NSLog(@"Enter region = %@", region);
}
- (void)didExitDensityRegion:(IAGSManager *)manager region:(IARegion *)region {
NSLog(@"Exit region = %@", region);
}
@end
Unregister a callback
Swift
// unregister delegate for subscription callback
IAGSManager.shared.removeGroundSageDelegate(self)
Objective-c
// unregister delegate for subscription callback
[[IAGSManager sharedManager] removeGroundSageDelegate:self];
Stop subscription
Swift
IAGSManager.shared.stopSubscription()
Objective-c
[[IAGSManager sharedManager] stopSubscription];