Import the NotifyVisitors SDK in your project
Download the sdk zip file from below which has some files library (.a file), header file (.h file), and some images (.png file), from the sdk download link and include them into your project. Simply drag and include them in your project.
Download SDK
1. Configure your info.plist
Open info.plist of your project as source code (right click on info.plist and click on Open as >> Source code) and add the following code in it.
Note:
In below example Dummy Brand ID and Secret keys shown. Kindly login to your account to see your credentials.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict/>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
<string>remote-notification</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>āYour Project Identifier Nameā</string>
<key>CFBundleURLSchemes</key>
<array>
<string>āyourURLschemeā</string>
</array>
</dict>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>location is required for geofence</string>
<key>nvBrandID</key>
<integer>Your BRANDID comes here</integer>
<key>nvSecretKey</key>
<string>Your SECRET KEY comes here</string>
<key>nvPushCategory</key>
<string>nvpush</string>
<key>nvViewAutoRedirection</key>
<true/> <!--OR--> <!-- <false/>-->
OR
You can simply open the info.plist and add the keys which works as same as above for this.
1.1 Add a new row by going to the menu and clicking Editor > Add Item. Setup a NSAppTransportSecurity
as a Dictionary
.
1.2 Added a Subkey called NSAllowsArbitraryLoads
as Boolean
and set its value to YES
as like following image.


1.3 Add a new row again and set up a URL Types item by adding a new item. Expand the URL Types key, expand Item 0
, and add a new item, URL schemes. Fill in āappSchemeā for Item 0 of URL schemes and your company identifier for the URL Identifier. Your file should resemble the image below when done.


1.4 Add a new row again and set up a NSLocationAlwaysUsageDescription
as String
and fill this field with the message you want to show in alert box for asking user permission for geofencing (example: location is required for geofence
)


1.5 Add a new row again and set up a nvBrandID
as Number
and fill this field with your BRANDID


1.6 Add a new row again and set up a nvSecretKey
as String and fill this field with your SECRET KEY
{8A991DED60F2186660EF8A337C30BDDE}


1.7 Add a new row again and set up a nvPushCategory
as String
and set itās value nvpush
.


1.8 Add a new row again and set up a key nvViewAutoRedirection
as Boolean
set it YES
to enable auto redirection of your appās ViewControllers
from sdk or set it NO
to handle redirections by your app.


1.9 Goto Capabilities
Tab and turn the Background Modes switch on.To do that select the project from the Project Navigator then select the app target then select the Capabilities tab, and turn the Background Modes switch on.Select 3 check boxes (i.e. Location updates
,Background fetch
,Remote notifications
).


In the Capabilities
Tab Turn On Push Notifications
and if you are upgraded Xcode 8.0 or later and Push Notifications was turned on in previous version turn off Push Notifications and turn on it again to configure push notification properly for the upgraded devices.


In the Capabilities Tab Turn On App Groups
and click on + sign and add a new app group give the group name as group.nv
.{Your App Bundle Identifier}.
Example : if Your App's Bundle Identifier is com.example.myapp then the App Group must be named as group.nv.com.example.myapp make sure this newly created app group must be checked (Turned on)


Import header file
Include the header file in`.m` file in which sdk function is to be accessed.
#import "notifyvisitors.h"
2. Initialise the SDK
Initialize the sdk in application didFinishLaunchingWithOptions
function.
- nvMode: Define a NSString nvMode and set its value ādebugā or āliveā based on preprocessor if condition so that sdk knows the app is running in debugging mode or downloaded from AppStore (i.e. live mode) as follows.
-(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
NSString *nvMode = nil;
#if DEBUG
nvMode = @"debug";
#else
nvMode = @"live";
#endif
[notifyvisitors Initialize:nvMode];
}
- Add the following method in application
didFinishLaunchingWithOptions
to register your app for push notification.
[notifyvisitors RegisterPushWithDelegate:self App:application launchOptions:launchOptions];
- Add the following three functions inside your
AppDelegate
file to handle the registering and receiving events of push notification.
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[notifyvisitors DidRegisteredNotification:application deviceToken:deviceToken];
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"push register failed due to the following error : %@", error);
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[notifyvisitors didReceiveRemoteNotificationWithUserInfo:userInfo];
}
- Add the following method in
applicationDidEnterBackground
in yourAppDelegate
file.
[notifyvisitors applicationDidEnterBackground: application];
- Add the following method in application
applicationDidBecomeActive
in yourAppDelegate
file.
[notifyvisitors applicationDidBecomeActive: application];
- Add the following method in
applicationWillTerminate
in yourAppDelegate
file.
[notifyvisitors applicationWillTerminate];
- Geo-fencing: To handle the geofencing notifications add the following Code to receive notification when geofencing events trigger.
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *) notification {
[notifyvisitors NotifyVisitorsGeofencingReceivedNotificationWithApplication:application window:self.window didReceiveGeofencingNotification:notification];
}
- Deep Linking: Use the following method in your
AppDelegate OpenURL
method that will check the deep linking and open your app from URL Scheme.
-(BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
[notifyvisitors OpenUrlWithApplication:application Url:url];
return YES; }
Updated 4 months ago
What's Next
Tracking Events |