После того, как я использую стратегию firebase
facebook
oauth
, чтобы зарегистрироваться как user
в моем приложении phonegap
(используя firebase authentication
), и он перенаправляет меня обратно в приложение, некоторые javascript выполняются в выполнить функцию native
ios
, которая загружает данные в UITableView
(данные, переданные с phonegap
), после перезагрузки UITableView
по какой-то причине загружается UITransitionView
и занимает место rootViewController
, полностью удалив UITabBarController
(rootViewController
) и заменив его пробелом UITransitionView
. Я постараюсь представить свой код, как он течет.
index.js - начальная точка iosNav.getCurrentTabControllerName()
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();
iosNav.getCurrentTabControllerName
относится к CDVPlugin
, что делает это:
#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];
}
}
Это getCurrentTabControllerName
на стороне js
:
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", []);
},
...
Хит pools.addPools()
, и это происходит:
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);
}
};
addPools
на стороне ios
(CDVPlugin
) выглядит следующим образом:
#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];
}
}
После всего этого я вижу, что все происходит правильно, потому что данные загружаются, я вижу консольное сообщение Item added!
, но затем неожиданно появляется пустое UITransitionView
и удаляет UITabBarController
, который был rootViewController
из window
. Единственный window
subview
после появления UITransitionView
- это UITransitionView
. Когда я enumerate
через window
subviews
и удаляю UITransitionView
, он выходит на пустой черный экран - что происходит? Спасибо.
UPDATE
Я понял, что могу избавиться от UITransitionView
, используя:
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] dismissViewControllerAnimated:false completion:nil]
но я бы предпочел, чтобы он вообще не появлялся ...