使用firebase
facebook
oauth
策略在我的user
应用(使用phonegap
)中注册为firebase authentication
后,它将我重定向回应用程序,执行了一些JavaScript,以执行native
ios
功能,该功能在{{之后,将数据加载到UITableView
(从phonegap
传递的数据)中1}}出于某种原因被重新加载,UITableView
被加载并代替了UITransitionView
,完全删除了rootViewController
(UITabBarController
),并将其替换带有空白的rootViewController
。我将尝试展示代码的流向。
index.js-起点是UITransitionView
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!
并删除了{{1} },即{{1}中的UITransitionView
。 UITabBarController
出现后唯一的rootViewController
window
是window
。当我通过subview
UITransitionView
UITransitionView
并移除enumerate
时,它进入黑屏-发生了什么?谢谢。
更新
我意识到我可以使用以下方法来摆脱window
:
subviews
但我希望它根本不显示...