Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = {
- user: null,
- // Application Constructor
- initialize: function () {
- this.bindEvents();
- },
- // Bind Event Listeners
- //
- // Bind any events that are required on startup. Common events are:
- // 'load', 'deviceready', 'offline', and 'online'.
- bindEvents: function () {
- document.addEventListener('deviceready', this.onDeviceReady, false);
- },
- // deviceready Event Handler
- //
- // The scope of 'this' is the event. In order to call the 'receivedEvent'
- // function, we must explicitly call 'app.receivedEvent(...);'
- onDeviceReady: function () {
- // Initialize Firebase
- // TODO: Replace with your project's customized code snippet
- var config = {
- apiKey: "AIzaSyAByGZpdKzSn2PLIDZxWtBw9dIMwxZLGNk",
- authDomain: "pool-3f2de.firebaseapp.com",
- databaseURL: "https://pool-3f2de.firebaseio.com",
- projectId: "pool-3f2de",
- storageBucket: "pool-3f2de.appspot.com",
- messagingSenderId: "843791335284",
- };
- firebase.initializeApp(config);
- app.receivedEvent('deviceready');
- },
- // Update DOM on a Received Event
- receivedEvent: function (id) {
- console.log('Received Event: ' + id);
- iosNav.getCurrentTabControllerName();
- }
- };
- app.initialize();
- #import "NavigationPlugin.h"
- @implementation NavigationPlugin
- -(void)getCurrentTabControllerName:(CDVInvokedUrlCommand*) command {
- NSLog(@"inside getCurrentTabController");
- NSString *className = NSStringFromClass([[self viewController] class]);
- NSLog(@"className: %@", className);
- CDVViewController* pvc = (CDVViewController*)[self viewController];
- NSDictionary* dict = @{@"className": className, @"webViewHidden": [NSNumber numberWithBool:[pvc.webView isHidden]]};
- if(className != nil) {
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dict];
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- } else {
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }
- }
- var iosNav = {
- getCurrentTabControllerName: function () {
- var win = function(d) {
- console.log("Current controller for tab: ", JSON.stringify(d));
- if(app.user != null) {
- firebase.auth().onAuthStateChanged(function(user) {
- if (user) {
- app.user = user;
- switch(d.className) {
- case "PoolsTableViewController":
- pools.addPools();
- //iosNav.hideWebView();
- break;
- case "PoolTableViewController":
- if(d.webViewHidden == true) {
- pool.addItems();
- //iosNav.hideWebView();
- }
- else {
- viewItem.retrieveItem();
- }
- break;
- default:
- // code block
- }
- }
- else {
- console.log("else of onAuthStateChanged for no user scenario");
- auth.presentLogin();
- }
- });
- }
- else {
- auth.presentLogin();
- }
- };
- var fail = function(e) {
- console.log(e);
- }
- cordova.exec(win, fail, "NavigationPlugin", "getCurrentTabControllerName", []);
- },
- ...
- var pools = {
- addPools: function() {
- var win = function(d) {
- console.log("Item added!", d);
- };
- var fail = function(e) {
- console.log(e)
- }
- var items = ["Hello", "How"];
- cordova.exec(win, fail, "ListPlugin", "addPools", items);
- }
- };
- #import "ListPlugin.h"
- @implementation ListPlugin
- -(void)addPools:(CDVInvokedUrlCommand*) command {
- NSArray* pools = command.arguments;
- //NSLog(@"argument: %@", [pools description]);
- NSLog(@"Subviews being described: %@", [[[[[UIApplication sharedApplication] delegate] window] subviews] description]);
- if(pools != nil || pools.count > 0) {
- NSLog(@"addpools %@", [pools description]);
- if([[self viewController] isKindOfClass:[PoolsTableViewController class]]) {
- PoolsTableViewController* pvc = (PoolsTableViewController*)[self viewController];
- [pools enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
- [pvc.pools addObject:obj];
- }];
- [pvc.tableView reloadData];
- }
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"pools"];
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- } else {
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }
- }
Add Comment
Please, Sign In to add comment