Guest User

Untitled

a guest
Jan 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. var app = {
  2. user: null,
  3. // Application Constructor
  4. initialize: function () {
  5. this.bindEvents();
  6. },
  7. // Bind Event Listeners
  8. //
  9. // Bind any events that are required on startup. Common events are:
  10. // 'load', 'deviceready', 'offline', and 'online'.
  11. bindEvents: function () {
  12. document.addEventListener('deviceready', this.onDeviceReady, false);
  13. },
  14. // deviceready Event Handler
  15. //
  16. // The scope of 'this' is the event. In order to call the 'receivedEvent'
  17. // function, we must explicitly call 'app.receivedEvent(...);'
  18. onDeviceReady: function () {
  19.  
  20. // Initialize Firebase
  21. // TODO: Replace with your project's customized code snippet
  22. var config = {
  23. apiKey: "AIzaSyAByGZpdKzSn2PLIDZxWtBw9dIMwxZLGNk",
  24. authDomain: "pool-3f2de.firebaseapp.com",
  25. databaseURL: "https://pool-3f2de.firebaseio.com",
  26. projectId: "pool-3f2de",
  27. storageBucket: "pool-3f2de.appspot.com",
  28. messagingSenderId: "843791335284",
  29. };
  30.  
  31. firebase.initializeApp(config);
  32.  
  33. app.receivedEvent('deviceready');
  34. },
  35. // Update DOM on a Received Event
  36. receivedEvent: function (id) {
  37. console.log('Received Event: ' + id);
  38.  
  39. iosNav.getCurrentTabControllerName();
  40. }
  41. };
  42.  
  43. app.initialize();
  44.  
  45. #import "NavigationPlugin.h"
  46.  
  47. @implementation NavigationPlugin
  48.  
  49. -(void)getCurrentTabControllerName:(CDVInvokedUrlCommand*) command {
  50. NSLog(@"inside getCurrentTabController");
  51.  
  52. NSString *className = NSStringFromClass([[self viewController] class]);
  53.  
  54. NSLog(@"className: %@", className);
  55.  
  56. CDVViewController* pvc = (CDVViewController*)[self viewController];
  57. NSDictionary* dict = @{@"className": className, @"webViewHidden": [NSNumber numberWithBool:[pvc.webView isHidden]]};
  58.  
  59. if(className != nil) {
  60. CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dict];
  61. [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
  62. } else {
  63. CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
  64. [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
  65. }
  66. }
  67.  
  68. var iosNav = {
  69. getCurrentTabControllerName: function () {
  70. var win = function(d) {
  71. console.log("Current controller for tab: ", JSON.stringify(d));
  72.  
  73. if(app.user != null) {
  74. firebase.auth().onAuthStateChanged(function(user) {
  75. if (user) {
  76. app.user = user;
  77.  
  78. switch(d.className) {
  79. case "PoolsTableViewController":
  80. pools.addPools();
  81. //iosNav.hideWebView();
  82. break;
  83. case "PoolTableViewController":
  84. if(d.webViewHidden == true) {
  85. pool.addItems();
  86. //iosNav.hideWebView();
  87. }
  88. else {
  89. viewItem.retrieveItem();
  90. }
  91. break;
  92. default:
  93. // code block
  94. }
  95. }
  96. else {
  97. console.log("else of onAuthStateChanged for no user scenario");
  98. auth.presentLogin();
  99. }
  100. });
  101. }
  102. else {
  103. auth.presentLogin();
  104. }
  105. };
  106. var fail = function(e) {
  107. console.log(e);
  108. }
  109.  
  110. cordova.exec(win, fail, "NavigationPlugin", "getCurrentTabControllerName", []);
  111. },
  112.  
  113. ...
  114.  
  115. var pools = {
  116. addPools: function() {
  117. var win = function(d) {
  118. console.log("Item added!", d);
  119. };
  120. var fail = function(e) {
  121. console.log(e)
  122. }
  123. var items = ["Hello", "How"];
  124. cordova.exec(win, fail, "ListPlugin", "addPools", items);
  125. }
  126. };
  127.  
  128. #import "ListPlugin.h"
  129.  
  130. @implementation ListPlugin
  131.  
  132. -(void)addPools:(CDVInvokedUrlCommand*) command {
  133. NSArray* pools = command.arguments;
  134. //NSLog(@"argument: %@", [pools description]);
  135.  
  136. NSLog(@"Subviews being described: %@", [[[[[UIApplication sharedApplication] delegate] window] subviews] description]);
  137.  
  138. if(pools != nil || pools.count > 0) {
  139. NSLog(@"addpools %@", [pools description]);
  140.  
  141. if([[self viewController] isKindOfClass:[PoolsTableViewController class]]) {
  142. PoolsTableViewController* pvc = (PoolsTableViewController*)[self viewController];
  143. [pools enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  144. [pvc.pools addObject:obj];
  145. }];
  146. [pvc.tableView reloadData];
  147. }
  148.  
  149. CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"pools"];
  150. [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
  151. } else {
  152. CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
  153. [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
  154. }
  155. }
Add Comment
Please, Sign In to add comment