- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我关注了谷歌分析 doc将它添加到我的 swift 应用程序中
我已经完成了那里所说的一切,但我的代码在运行时失败了。
这是我在 AppDelegate 中的代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
loadGoogleAnalytics()
chooseAndLuanchStoryboard()
initMembersAfterViewControllerInit()
return true
}
func loadGoogleAnalytics()
{
// Configure tracker from GoogleService-Info.plist.
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
// Optional: configure GAI options.
let gai = GAI.sharedInstance()
gai.trackUncaughtExceptions = true // report uncaught exceptions
gai.logger.logLevel = GAILogLevel.Error
}
这是我在 ViewController 中的代码:
override public func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
let name = "Pattern~\(self.title!)"
// The UA-XXXXX-Y tracker ID is loaded automatically from the
// GoogleService-Info.plist by the `GGLContext` in the AppDelegate.
// If you're copying this to an app just using Analytics, you'll
// need to configure your tracking ID here.
// [START screen_view_hit_swift]
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: name)
let builder = GAIDictionaryBuilder.createScreenView()
tracker.send(builder.build() as [NSObject : AnyObject])
// [END screen_view_hit_swift]
}
override public func viewWillDisappear(animated: Bool) {
keyboardManager.deregisterFromKeyboardNotifications()
stopRefreshTimer()
}
我收到此运行时错误,因为 let name = "Pattern~\(self.title!)"
中的 self.title
为零
2016-02-05 19:44:44.377 Inline[95803:3750273] The configuration file 'GoogleService-Info.plist' is for another bundle identifier ('com.Inline.inline-ios'). Using this file the services may not be configured correctly. To continue with this configuration file, you may change your app's bundle identifier to 'com.Inline.inline-ios'. Or you can download a new configuration file that matches your bundle identifier from https://developers.google.com/mobile/add and replace the current one.
2016-02-05 19:44:44.383 Inline[95803:] <GMR/INFO> App measurement v.1302000 started
2016-02-05 19:44:44.384 Inline[95803:] <GMR/INFO> To enable debug logging set the following application argument: -GMRDebugEnabled (see http://goo.gl/Y0Yjwu)
2016-02-05 19:44:45.999 Inline[95803:] <GMR/INFO> App measurement enabled
2016-02-05 19:44:46.034 Inline[95803:3750273] Unknown class logo in Interface Builder file.
2016-02-05 19:44:46.048 Inline[95803:3750273] Failed to set (keyPath) user defined inspected property on (UIView): [<UIView 0x7faf9a079730> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.
2016-02-05 19:44:46.048 Inline[95803:3750273] Failed to set (keyPath) user defined inspected property on (UIView): [<UIView 0x7faf9a0729a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.
2016-02-05 19:44:46.048 Inline[95803:3750273] Failed to set (keyPath) user defined inspected property on (UIView): [<UIView 0x7faf9a07f8b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.
2016-02-05 19:44:46.051 Inline[95803:3750273] Device ID: (null)
2016-02-05 19:44:46.051 Inline[95803:3750273] RegisterDevice RPC request
scanning for beacons
fatal error: unexpectedly found nil while unwrapping an Optional value
如何使 self.title
不为零?
最佳答案
在 didFinishLaunchingWithOptions
上初始化
let gai = GAI.sharedInstance()
let id = "UA-ID"
gai.trackerWithTrackingId(id)
gai.trackUncaughtExceptions = true
gai.logger.logLevel = GAILogLevel.Warning
gai.defaultTracker.allowIDFACollection = false
通过 viewDidAppear
上的 setScreenName
调用谷歌分析的简单方法。
extension UIViewController {
func setScreeName(name: String) {
self.title = name
self.sendScreenView()
}
func sendScreenView() {
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: self.title)
let builder = GAIDictionaryBuilder.createScreenView()
tracker.send(builder.build() as [NSObject : AnyObject])
}
func trackEvent(category: String, action: String, label: String, value: NSNumber?) {
let tracker = GAI.sharedInstance().defaultTracker
let trackDictionary = GAIDictionaryBuilder.createEventWithCategory(category, action: action, label: label, value: value)
tracker.send(trackDictionary.build() as [NSObject : AnyObject])
}
}
关于ios - viewController.title 在 Google Analytics 初始化后为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35230442/
有什么方法可以覆盖无法直接编辑的页面标题,只能在页眉中添加 Javascript? 我不能直接编辑的行是: Title of the page 我能想到的解决这个问题的唯一方法是在我可以通过我的门户后
这是我的基础文件 {% load static %} {% include "feed/header.html" %} {% block content%} {% endblock %} {% inc
请说明 之间有什么区别标记和 标签。 Page title 如果两者都使用,哪个最优先? 我观察到一些网站同时具有 和 tags 和 两者相同,这是预期的,请确认? 如果我们不使用 标签标题,我
我有一个带有唯一title的表_primary,并且我有一个需要设置引用title的表_secondary > 对于 _primary 表。 最佳答案 尝试这个解决方案并让我知道它对您有用。 ALTE
我正在尝试学习使用 PDO 而不是 MySQLi 进行数据库访问,但我在从数据库中选择数据时遇到了问题。我想使用: $STH = $DBH->query('SELECT * FROM ratings
我了解 title 和 alt 属性的用途,但我只是不了解它们的最佳用途,或者我是否可以使用相同的 title /alt 不止一次。 例如,以一个关于狗的网站为例: 根据我的理解,所有 img 标签都
我分配了一个带有标题 (initWithTitle) 的 UITabBarItem 并将其连接到 UINavigationController。 我发现,如果导航 Controller 的 Root
我有标签栏和导航栏。在导航栏中我有表格 View 。问题是,当我在 IB 中将标题设置为选项卡栏,然后在 TableView 中设置标题时,选项卡栏标题将更改为 TableView 中的标题,并且我在
在我的 JSP 页面中,我使用 显示页面标题,有时可以,但有时页面显示无法cpmplie代码 。所以我将代码更改为 ${TITLE} ,也可以。 有什么不同和${TITLE}在jsp中? 这是我的页
我目前正在向 Jade 和 node.js 介绍自己 由于我想避免冗余,我想到将域名附加到当前标题,例如Blog | example.com 我的 Jade 模板得到了 Blog通过 Node.js
//Sorting userDefined object from ArrayList<>... import java.io.*; import java.util.*; class Song
我的网站有这两个元标记,它们目前具有相同的值: 第二个是 facebook 连接所需的格式。 这是否意味着第一个是多余的并且可以删除? 最佳答案 最好同时存在这两个标签。该标签告诉搜索引擎有
我现在对 ASP.NET MVC 的 Razor ViewEngine 感到困惑。 大多数人会说: View.Title 与相同 ViewData["Title"] 运行应用程序后我得到了这个 Com
UIViewController 的 title 属性的用途是什么,不能用 navigationItem.title 设置标题吗? 两者似乎都有效,我只是想知道为什么会有这种看似重复的功能。 最佳答案
我仍在学习如何将 API 数据与 react 和 nextjs 一起使用。但是,为什么我的函数只在我编写 {props.props.title} 而不是我期望的 {props.title} 时起作用?
我正在尝试编写一个从URL提取的正则表达式,但是问题是“。”与我们已经知道的不匹配换行符。如何编写正则表达式以匹配和提取pageTitle(。*?),但换行符可能介于 我在用grails。 最佳答案
我仍在学习如何将 API 数据与 react 和 nextjs 一起使用。但是,为什么我的函数只在我编写 {props.props.title} 而不是我期望的 {props.title} 时起作用?
我正在 github 上创建一个库,所以我为此使用了一个 Markdown 文件,其结构如下: # My main title ## My first section ... ## My second
我在某些地方看到,为了从 props 中获取 title 的值,我们使用 {`${props.title} `} 而在其他一些地方,我们使用它 {props.title} 有什么区别? 最佳答案 第一
我想使用 IMG 标签的 TITLE 属性,为图像创建标题: HTML CSS img[title]:after{content:attr(title);} 但是无论是在 IE、Firefox 还是
我是一名优秀的程序员,十分优秀!