我一直在努力在我的应用程序中包含动态链接。我已经对其进行了设置,以便可以正确生成和接收链接,但它们仅在应用程序打开并在后台运行时才有效。如果应用程序完全关闭,则链接只会打开应用程序。看起来它没有调用 AppDelegate 中的 continueUserActivity 方法,即使我在 didFinishLaunchingWithOptions 方法中返回 TRUE。我已经读到我应该在 didFinishLaunchingWithOptions 方法中获取传入的 URL,但是可用的答案不起作用并且已经过时,所以我希望有人会知道。
这是代码:
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate{
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let incomingURL = userActivity.webpageURL {
let linkHandled = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in
guard error == nil else {
print(error!.localizedDescription) …
Run Code Online (Sandbox Code Playgroud) deep-linking firebase swift firebase-dynamic-links uiscenedelegate
我正在将一个位置传递给另一个UIViewController
有MapView
使用的位置prepareForSegue
.我叫这个receivedLocation
.地图以传递的位置为中心.如果用户单击某个按钮将其带到地图而不先发送位置,这不会失败吗?
如何测试是否receivedLocation
实际包含数据,以便我可以将地图设置为以其他内容为中心(如果它是空的)?
是否会创建一个布尔变量,并且最初将其设置为false,但在传递位置并按照我的意愿测试该工作时将其设置为true ?
我看到有一些叫做CLLocationCoordinateIsValid
可用的东西,但它的参数是2DCoordinate,我遇到了同样的测试问题receivedLocation
.
我对此很新,并试图寻找答案,但找不到合适的答案.谢谢!
import UIKit
import MapKit
import CoreLocation
class mapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet var map: MKMapView!
@IBOutlet var notes: UITextView!
var receivedLocation = CLLocation()
var annotation = MKPointAnnotation()
var currentManager:CLLocationManager!
var latitute:CLLocationDegrees = CLLocationDegrees()
var longitude:CLLocationDegrees = CLLocationDegrees()
override func viewDidLoad() {
super.viewDidLoad()
map.layer.cornerRadius = 12.0
notes.layer.cornerRadius = 12.0
currentManager = CLLocationManager()
currentManager.delegate = self
currentManager.desiredAccuracy = kCLLocationAccuracyBest …
Run Code Online (Sandbox Code Playgroud) 我之前使用过计时器并且他们工作过,但自从NSTimer改为Timer后,我的计时器拒绝工作.我试过的代码如下:
override func viewDidLoad() {
super.viewDidLoad()
_ = Timer(timeInterval: 3, target: self, selector: #selector(test), userInfo: nil, repeats: true)
}
func test() {
print("The timer worked")
}
Run Code Online (Sandbox Code Playgroud)
从未调用测试函数,我不知道为什么.我也尝试过初始化它并像这样使用它:
var followUpTimer:Timer!
override func viewDidLoad() {
super.viewDidLoad()
followUpTimer = Timer(timeInterval: 3, target: self, selector: #selector(test), userInfo: nil, repeats: true)
}
func test() {
print("The timer worked")
}
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.我究竟做错了什么?我在网上找到的所有答案都表明这是正确的做法.
我正在尝试复制导入脚本,以将我的Firebase RTD数据发送到Algolia。尝试运行该脚本时,它失败并表示dotenv.load不是函数。
我的.env文件与index.js文件位于同一目录中。我尝试过移动.env文件,但这无济于事。这是index.js的开始代码:
const algoliasearch = require('algoliasearch');
const dotenv = require('dotenv');
const firebase = require('firebase');
//load values from the ./env file in this direcotry into process.env
dotenv.load();
//config firebase
firebase.initializeApp({
databaseURL: process.env.FIREBASE_DATABASE_URL,
});
Run Code Online (Sandbox Code Playgroud)
我能做什么?根据要求使用.config()也不起作用。
我刚开始使用Realm 2.0.4和Xcode 8,它运行良好.今天我更新到Xcode 8.1,它不再编译.我得到一个错误说"使用Swift 3.0编译的模块无法在Swift 3.0.1中导入."
我怎样才能解决这个问题?我已从嵌入式框架表中删除了Realm.framework和RealmSwift.framework,并删除了3.0.1版本,但问题仍然存在.我删除了DerivedData文件夹,但它不起作用.
我该怎么办?我没有使用CocoaPods或Carthage.
我试图在下载其图像时在每个集合视图单元格中放置一个UIActivityIndicatorView.我把它出现在每个细胞中,但它拒绝自我中心.它停留在左上角.我怎样才能让它正确居中?
我是这样做的:
extension UIView {
func showActivityIndicator(onView: UIView, withIndicator: UIActivityIndicatorView) {
withIndicator.frame = CGRect(x: onView.frame.midX - 20, y: onView.frame.midY - 20, width: 40, height: 40)
withIndicator.activityIndicatorViewStyle = .whiteLarge
withIndicator.center = onView.center
onView.addSubview(withIndicator)
withIndicator.startAnimating()
}
}
Run Code Online (Sandbox Code Playgroud)
我在cellForItemAtIndexPath中调用该函数,如:
showActivityIndicator(onView: cell.contentView, withIndicator: activityInd)
Run Code Online (Sandbox Code Playgroud)
但我所做的一切都不会从左上角移动它.有什么建议?