创建用户时尝试更新实时数据库中的用户数据.这是我的代码:
const functions = require('firebase-functions');
const promise = require('request-promise');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var omitBy = require('lodash.omitby');
var isNil = require('lodash.isnil');
'use strict';
exports.userCreated = functions.auth.user().onCreate(event => {
let request = admin.auth().getUser(event.data.uid)
.then(function(user) {
console.log("Successfully fetched user data: ", user.toJSON());
var email, firstName, lastName, photoURL;
for (var provider of user.providerData) {
if (provider.email) {
email = provider.email;
}
if (provider.photoURL) {
photoURL = provider.photoURL;
}
if (provider.displayName) {
const names = provider.displayName.split(' ');
firstName = names[0];
if (names.length > …Run Code Online (Sandbox Code Playgroud) javascript facebook firebase firebase-authentication google-cloud-functions
我正在努力将我的项目从AFNetworking转移到Alamofire.真的很喜欢这个项目.POST请求工作正常,但是,我在尝试发出GET请求时收到此错误.
这是一些示例代码:
class func listCloudCredntials(onlyNew onlyNew: Bool = true, includePending: Bool = true) -> Request {
let parameters: [String: AnyObject] = includePending ? ["include_pending": "true"] : [:]
let urlString = "https://myapp-staging.herokuapp.com/api/1/credntials"
let token = SSKeychain.storedToken()
let headers: [String: String] = ["Authorization": "Bearer \(token)"]
return Alamofire.request(.GET, urlString, parameters: parameters, encoding: .JSON, headers: headers)
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误: -1005 The network connection was lost
但是,如果我将请求类型更改为.POST,则请求"正常".我收到401代码,但至少请求不会丢失网络连接.
我究竟做错了什么?
我正在使用AFNetworking进行POST请求.我需要等到完成块完成才能返回数据,我遇到了问题.
我有一个解决方案,直到我切换到AFNetworking:
int i = 0;
while (!done)
{
[NSRunLoop.currentRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
i++;
NSLog(@"While Loop:%i", i);
if (i == 149) //request timed out
done = YES;
}
Run Code Online (Sandbox Code Playgroud)
现在,解决方案偶尔会起作用.有时它只用NSLog(@"While Loop:%i", i);1或2记录完成,但有时它会记录到149并超时.似乎NSRunLoop有时会在不同的线程中运行,但有时会在阻止我的请求的同一线程上运行.
这是我目前的代码:
- (id)postRequestWithBaseURLString:(NSString *)baseURLString function:(NSString *)function parameters:(NSDictionary *)parameters
{
if (baseURLString)
function = [baseURLString stringByAppendingString:function];
__block BOOL done = NO;
__block id returnObject = nil;
[self.manager POST:function parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"Success: %@", responseObject);
done = YES;
returnObject = responseObject;
}
failure:^(AFHTTPRequestOperation *operation, NSError …Run Code Online (Sandbox Code Playgroud) 我在我的AppDelegate.m文件中有这个代码,didFinishLaunchingWithOptions:以便我可以有一个自定义字体.
[[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor grayColor], UITextAttributeTextColor,
[UIFont fontWithName:@"Gotham-Medium" size:10], UITextAttributeFont, nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont fontWithName:@"Gotham-Medium" size:10], UITextAttributeFont, nil] forState:UIControlStateHighlighted];
Run Code Online (Sandbox Code Playgroud)
字体更改按预期工作,但我在调试控制台中获得此输出:
button text attributes only respected for UIControlStateNormal, UIControlStateHighlighted and UIControlStateDisabled. state = 1 is interpreted as UIControlStateHighlighted.
我在我的App Delegate中有这个代码:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Nav Bar.png"] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
这很好用,但我使用它MFMailComposeViewController,我希望它具有默认的NavigationBar外观.
我怎么做?
编辑:
我试过这段代码:
[[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], [UIViewController class], nil] setBackgroundImage:[UIImage imageNamed:@"Textured Background.png"] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
我也试过只有这个代码.没有什么变化.默认导航栏,包括邮件视图控制器.
我认为它可能与之相关appearanceWhenContainedIn:.有谁知道MFMailComposeViewController会包含什么?
有没有办法同时设置多个属性?我试过这个:
dateTextField.font, nameTextField.font = [UIFont fontWithName:@"Gotham-Book" size:16];
Run Code Online (Sandbox Code Playgroud)
但这得到了警告.我还能做些什么吗?
我有一个UITextView。我将委托myTextView设置为self,当我进行正常编辑时,此方法调用得很好:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(@"Called");
}
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我调用我的代码:[myTextView insertText:@"Hello World"];。textView:shouldChangeTextInRange:replacementText:当我这样做时,我需要在插入文本后调用。我该怎么做呢?
ios ×6
objective-c ×4
afnetworking ×1
alamofire ×1
facebook ×1
firebase ×1
javascript ×1
mfmailcomposeviewcontroller ×1
rest ×1
swift ×1
uifont ×1
uitabbaritem ×1
uitextview ×1
xcode ×1