小编Mik*_*keG的帖子

Firebase的云功能 - 序列化返回值时出错:

我有一个云函数,用于交叉引用两个列表,并查找列表中彼此匹配的值.该功能似乎工作正常,但在日志中我一直看到这一点Error serializing return value: TypeError: Converting circular structure to JSON.这是功能......

exports.crossReferenceContacts = functions.database.ref('/cross-ref-contacts/{userId}').onWrite(event => {

    if (event.data.previous.exists()) {
        return null;
    }

    const userContacts = event.data.val();
    const completionRef = event.data.adminRef.root.child('completed-cross-ref').child(userId);
    const removalRef = event.data.ref;

    var contactsVerifiedOnDatabase ={};
    var matchedContacts= {};


    var verifiedNumsRef = event.data.adminRef.root.child('verified-phone-numbers');
    return verifiedNumsRef.once('value', function(snapshot) {

        contactsVerifiedOnDatabase = snapshot.val();

        for (key in userContacts) {
            //checks if a value for this key exists in `contactsVerifiedOnDatabase`
            //if key dioes exist then add the key:value pair to matchedContacts
        };

        removalRef.set(null); …
Run Code Online (Sandbox Code Playgroud)

javascript node.js firebase firebase-realtime-database google-cloud-functions

15
推荐指数
2
解决办法
2657
查看次数

每次点击取消按钮时,搜索栏会向下跳一行

我已经实现了一个UISearchBar来搜索外部API中的项目目录.搜索功能按预期工作,但问题是,每次按下取消按钮(位于搜索栏文本字段的右侧)时,整个搜索栏向下移动一行,看起来它会推动整个表视图也是如此.

因此,如果我在搜索栏文本字段中键入一个字母,然后按取消,搜索栏文本字段向下移动44px,这是行高,并且表视图本身也会被按下相同的量.如果我连续按类型,然后按取消,搜索栏将在视图中进一步向下移动.任何建议都会很棒!这是我的代码:

import Foundation
import UIKit
import ItemLogger


private extension Selector {
    static let dismiss = #selector(SearchVC.dismissView)
}


extension SearchVC: UISearchResultsUpdating {
    func updateSearchResultsForSearchController(searchController: UISearchController) {
        let searchBar = searchController.searchBar
        let scope = searchBar.scopeButtonTitles![searchBar.selectedScopeButtonIndex]
        filterContentForSearchText(searchController.searchBar.text!, scope: scope)
    }
}
extension SearchVC: UISearchBarDelegate {
    func searchBar(searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
        filterContentForSearchText(searchBar.text!, scope: searchBar.scopeButtonTitles![selectedScope])
    }
}

class SearchVC: UITableViewController {

    let searchController = UISearchController(searchResultsController: nil)
    var searchedItems = [ItemLog]()
    var searchedImages = [UIImage]()

    override func viewDidLoad() {
        super.viewDidLoad()

        let leftBarButtonItem = …
Run Code Online (Sandbox Code Playgroud)

uisearchbar ios swift uisearchcontroller

8
推荐指数
1
解决办法
3335
查看次数

可以在后台运行应用程序时运行CADisplayLink吗?

我在应用程序中使用CADisplayLink作为计时器。我之所以使用CADisplayLink,是因为我的应用非常依赖CADisplayLink的准确性/准确性。在我看来,NSTimer不是合适的替代品。

问题是,有时我需要CADisplayLink在应用程序处于后台时触发并调用其选择器。这有可能吗?我知道CADisplayLink链接到应用程序UI的刷新率。这是否意味着当我的应用程序在后台运行时,没有UI,因此在这种情况下无法使用CADisplayLink?或者,是否可以通过更改添加到其中的运行循环或通过更改forMode参数来以某种方式使用CADisplayLink ?还是使用某些GCD欺骗/变通方法?

注意:我的应用程序正在使用AudioPlayer,因此启用了后台功能。我可以在后台运行其他代码。为了测试,我用NSTimer切换了CADisplayLink,然后触发了NSTimer并调用了它的选择器。我只是无法启动CADisplayLink,也找不到任何有关在后台使用CADisplayLink的权威性文档

这是与显示链接有关的当前代码:

func beginTimer(){

  dispatch_async(dispatch_get_main_queue()){
      self.displayLink = CADisplayLink(target: self, selector: "update")
      self.displayLink.addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
  }
}

func update(){
  delegate?.executeCallback
 }
Run Code Online (Sandbox Code Playgroud)

ios cadisplaylink swift background-mode

5
推荐指数
1
解决办法
1047
查看次数

InputToolbar发送按钮不起作用

我正在使用JSQMessagesViewController和Firebase在我的应用程序中实现聊天功能.我的ChatViewController中的一切都运行良好.但是现在我已经将我的ChatViewController移动到父视图控制器内的容器视图中,现在当扩展键盘时"发送"按钮不起作用.

换句话说,为了发送聊天消息,我必须调用view.endEditing(true)它本身在UITabBarController中的父视图控制器,然后发送按钮将起作用.但只要键盘展开,发送按钮就不会响应.下面是我的ChatViewController代码...

import Foundation
import UIKit
import FirebaseDatabase
import JSQMessagesViewController


final class ChatViewController: JSQMessagesViewController {

    var outgoingBubbleImageView: JSQMessagesBubbleImage!
    var incomingBubbleImageView: JSQMessagesBubbleImage!
    var fireRootRef: FIRDatabaseReference!
    var chatMessages = [JSQMessage]()
    var messagesRefHandle: UInt!
    var chatChannelId: String!


    override func viewDidLoad(){
        super.viewDidLoad()
        self.inputToolbar.contentView.textView.backgroundColor = UIColor.clear
        inputToolbar.alpha = 0.7
        ...
    }


    override func viewWillAppear(_ animated: Bool){
        super.viewWillAppear(animated)
    }

    override func viewDidAppear(_ animated: Bool){
        super.viewDidAppear(animated)
    }


    func setupView(){
     ...
    }    

    override func viewWillDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        removeChatObserver()
    }

    func removeChatObserver(){
       ...
    }

    private …
Run Code Online (Sandbox Code Playgroud)

ios swift jsqmessagesviewcontroller

5
推荐指数
1
解决办法
696
查看次数

音频播放锁定屏幕控制不在iPhone上显示

我在我的iPhone 6s设备上使用iOS 10.2进行测试.

我正在播放流式音频,能够播放/暂停音频,跳过曲目等.我还启用了背景模式,音频在后台播放并继续正确播放播放列表.我唯一的问题是让锁屏控件显示出来.什么都没有显示......

在我的MainViewController的viewDidLoad()中,当我的应用程序启动时,我称之为...

 func setupAudioSession(){

   UIApplication.shared.beginReceivingRemoteControlEvents()


   do {
       try    AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: AVAudioSessionCategoryOptions.mixWithOthers)

       self.becomeFirstResponder()

       do {
           try AVAudioSession.sharedInstance().setActive(true)
                   print("AVAudioSession is Active")
       } catch let error as NSError {
                   print(error.localizedDescription)

       }
   } catch let error as NSError {
               print(error.localizedDescription)
   }
}
Run Code Online (Sandbox Code Playgroud)

在我开始播放音频之后,在我的AudioPlayer课程中,我打电话给...

func setupLockScreen(){
       let commandCenter = MPRemoteCommandCenter.shared()
       commandCenter.nextTrackCommand.isEnabled = true
       commandCenter.nextTrackCommand.addTarget(self, action:#selector(skipTrack))
       MPNowPlayingInfoCenter.default().nowPlayingInfo = [MPMediaItemPropertyTitle: "TESTING"]
}
Run Code Online (Sandbox Code Playgroud)

当我锁定iPhone然后再次点击电源按钮进入锁定屏幕时,根本不显示音频控件.好像没有播放音频,我只看到我正常的背景照片.此外,控制面板中不显示任何控件(在主屏幕上向上滑动,然后向左滑动到音乐控件所在的位置).

问题是因为我没有使用AVAudioPlayer或AVPlayer?但是,例如,Spotify如何使用他们自己的自定义音频播放器来显示锁定屏幕控件?感谢您的任何建议/帮助

audio media-player ios swift

5
推荐指数
1
解决办法
2064
查看次数

Firebase云功能无法正确记录

我正在创建一个社交应用程序,朋友可以在其中通过通讯录找到彼此。本质上,我有两个很长的电话号码列表,并且我想使用firebase-cloud-function查找两个列表中都存在的所有号码。

为此,我将用户的所有联系信息发布到Firebase Realtime数据库,并触发了云功能(.onWrite)。cloud函数获取所有刚刚发布的电话号码,然后检索数据库中所有已验证的电话号码,然后需要交叉引用这两个列表以查找所有匹配项。

这是我的代码...

 exports.crossReferenceContacts = functions.database.ref('/cross-ref-contacts/{userId}').onWrite(event => {

    //if it already existed then this function triggered beacuse we are calling set(null) and thus we dont want to proceed
    if (event.data.previous.exists()) {
        console.log("PREVIOUSLY EXISTED. RETURN NULL!!!");
        return null;
    }

    const userId = event.params.userId;
    const userContacts = event.data.val();

    var contactsOnPhone = [];
    var contactsVerifiedInDatabase =[];
    var matchedContacts= [];

    for (var key in userContacts){
        let contact = new Object();
        contact.contactName = userContacts[key];
        contact.number = key;
        contactsOnPhone.push(contact);
    };

    var verifiedNumsRef = event.data.adminRef.root.child('verified-phone-numbers');
    return …
Run Code Online (Sandbox Code Playgroud)

node.js firebase firebase-realtime-database

4
推荐指数
1
解决办法
2702
查看次数

Firebase 身份验证模拟器电子邮件/密码登录 REST 端点

我可以使用此端点https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[API-KEY](在这些文档@ 部分使用电子邮件/密码登录)通过 HTTP 请求登录 Firebase 身份验证用户。

无论如何,是否可以在 Firebase 身份验证模拟器上完成此操作 - 是否有一个模拟器 REST 端点可以提供相同的功能?

当我在端口 9099 上运行身份验证模拟器时,我尝试过 -
. http://localhost:9099/v1/accounts:signInWithPassword?key=[API-KEY]
. http://localhost:9099/emulator/v1/accounts:signInWithPassword?key=[API-KEY]
. http://identitytoolkit.localhost:9099/emulator/v1/accounts:signInWithPassword?key=[API-KEY]
.http://localhost:9099/identitytoolkit/v3/relyingparty/verifyPassword?key=[API-KEY]

但没有工作。有任何想法吗?

这是我对这些请求中的每一个得到的回应 -

{
    "error": {
        "code": 404,
        "message": "Not Found",
        "errors": [
            {
                "message": "Not Found",
                "reason": "notFound"
            }
        ],
        "status": "NOT_FOUND"
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:也试过这个: http://localhost:9099/identitytoolkit.googleapis.com/v1/projects/emulator-test-project-id/accounts?key=[API-KEY]

但得到回应

{
    "error": {
        "code": 400,
        "message": "INSUFFICIENT_PERMISSION : Only authenticated requests can specify target_project_id.",
        "errors": [
            {
                "message": "INSUFFICIENT_PERMISSION : Only …
Run Code Online (Sandbox Code Playgroud)

firebase-tools firebase-authentication

3
推荐指数
1
解决办法
398
查看次数

C,错误:getline的冲突类型

有人可以看看这个并告诉我有什么问题.我有3个错误.1)error: Conflicting types for getline2)error: too few arguments to function call, expected 3 have 23)error: conflicting types for getline.我确定我忽略了一些简单但我无法找到错误的东西.谢谢,这是代码......

#include <stdio.h>

#define MAXLINE 1000

int getline(char line[], int maxline); /*conflicting types for getline*/
void copy(char to[], char from[]);

main(){

int len;
int max;
char line[MAXLINE];
char longest[MAXLINE];

max = 0;

while((len = getline(line, MAXLINE)) > 0)/*too few arguments to call, expected 3 have 2*/
    if (len > max){
        max = len;          
        copy(longest, line);
    } …
Run Code Online (Sandbox Code Playgroud)

c kernighan-and-ritchie

2
推荐指数
2
解决办法
582
查看次数

无法对不可变值使用变异成员:“self”是不可变的

我不明白为什么我会收到此错误。SomeController是一个类,而不是一个结构,并且它不是不可变的。有解决办法吗?

class SomeController: APIFetchable {

    let baseUrl = "https://jsonplaceholder.typicode.com"
    let defaultSession =  URLSession(configuration: .default)
    var dataTask: URLSessionTask?

    func fetchDataFromAPI(atPath path: String, _ callback: ()-> Void){
        fetchDataAtPath(path) { data, error in  /*Error on this line -> "Cannot use mutating member on immutable value: 'self' is immutable"*/

        }
    }

}


protocol APIFetchable {
    var baseUrl: String {get}
    var defaultSession: URLSession {get}
    var dataTask: URLSessionTask? {get set}

    mutating func fetchDataAtPath(_ path: String,  _ callback: @escaping (Data?, Error?)-> Void)
}

extension APIFetchable …
Run Code Online (Sandbox Code Playgroud)

swift protocol-oriented swift4

2
推荐指数
1
解决办法
5546
查看次数