- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
从 Crashlytics
,我们在 Google 登录过程中收到大量崩溃报告。崩溃报告如下:
Fatal Exception: NSInvalidArgumentException
uiDelegate must either be a |UIViewController| or implement the |signIn:presentViewController:| and |signIn:dismissViewController:| methods from |GIDSignInUIDelegate|.
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x1837f2db0 __exceptionPreprocess
1 libobjc.A.dylib 0x182e57f80 objc_exception_throw
2 CoreFoundation 0x1837f2cf8 -[NSException initWithCoder:]
3 Hello English 0x100583d18 -[GIDSignIn assertValidUIDelegate] (GIDSignIn.m:512)
4 Hello English 0x1005861dc -[GIDSignIn signInWithOptions:] (GIDSignIn.m:961)
5 Hello English 0x10058a0e4 -[GIDSignInButton pressed] (GIDSignInButton.m:385)
6 UIKit 0x188988be8 -[UIApplication sendAction:to:from:forEvent:]
7 UIKit 0x188988b64 -[UIControl sendAction:to:forEvent:]
8 UIKit 0x188970870 -[UIControl _sendActionsForEvents:withEvent:]
9 UIKit 0x188988454 -[UIControl touchesEnded:withEvent:]
10 UIKit 0x188988084 -[UIWindow _sendTouchesForEvent:]
11 UIKit 0x188980c20 -[UIWindow sendEvent:]
12 UIKit 0x18895104c -[UIApplication sendEvent:]
13 UIKit 0x18894f628 _UIApplicationHandleEventQueue
14 CoreFoundation 0x1837a909c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
15 CoreFoundation 0x1837a8b30 __CFRunLoopDoSources0
16 CoreFoundation 0x1837a6830 __CFRunLoopRun
17 CoreFoundation 0x1836d0c50 CFRunLoopRunSpecific
18 GraphicsServices 0x184fb8088 GSEventRunModal
19 UIKit 0x1889ba088 UIApplicationMain
20 Hello English 0x10029b2cc main (AppDelegate.swift:26)
21 libdispatch.dylib 0x18326e8b8 (Missing)
到目前为止我们已经尝试过:
GIDSignIn.sharedInstance().uiDelegate = self
从 viewDidLoad()
移动到 viewDidAppear(animated: Bool)
GIDSignInUIDelegate
的所有三种方法,但没有成功。UIViewController
的直接子级,但现在它是并且崩溃仍在计数。UIButton
,因此我们认为这可能是导致崩溃的原因(虽然不合逻辑,但我们尝试过);我们将其更改为 GIDSignInButton
,但没有减少崩溃次数。目前我们已经删除了 Google Login
过程,但这不是解决方案。奇怪的是,我们最终无法重现这次崩溃;我们仅在 Crashlytics
上遇到这些崩溃。
所以有人有任何解决方案吗?
最佳答案
经过一番努力终于找到了解决办法。我的环境是
swift 3,
iOS 10.3.x,
Xcode 8.3.2
在这里发布一个完整的解决方案
import UIKit
import GoogleSignIn
class ViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate {
@IBOutlet weak var signInButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// set delegates
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
let buttonFrame : CGRect = CGRect.init(x: 0, y: 0, width: 100, height: 50)
let gdSignInButton = GIDSignInButton.init(frame:buttonFrame)
gdSignInButton.center = view.center
view.addSubview(gdSignInButton)
// gdSignInButton.addTarget(self, action: #selector(self.didTapSignOut(sender: self.gdSignInButton)), for: UIControlEvents.touchUpInside)
}
@IBAction func didTapSignOut(sender: GIDSignInButton) {
GIDSignIn.sharedInstance().signOut()
}
func sign(inWillDispatch signIn: GIDSignIn!, error: Error!) {
guard error == nil else {
print("Error while trying to redirect : \(error)")
return
}
print("Successful Redirection")
}
//MARK: GIDSignIn Delegate
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)
{
if (error == nil) {
// Perform any operations on signed in user here.
let userId = user.userID // For client-side use only!
print("User id is \(userId)")
let idToken = user.authentication.idToken // Safe to send to the server
print("Authentication idToken is \(idToken)")
let fullName = user.profile.name
print("User full name is \(fullName)")
let givenName = user.profile.givenName
print("User given profile name is \(givenName)")
let familyName = user.profile.familyName
print("User family name is \(familyName)")
let email = user.profile.email
print("User email address is \(email)")
// ...
} else {
print("ERROR ::\(error.localizedDescription)")
}
}
// Finished disconnecting |user| from the app successfully if |error| is |nil|.
public func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!)
{
}
}
我的 AppDelegate 看起来像这样。
import UIKit
import Google
import GoogleSignIn
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Initialize sign-in
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL!,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
}
关于ios - Swift - uiDelegate 必须是 UIViewController 或实现 signIn :presentViewController: & signIn:dismissViewController: methods,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39888816/
假设我有一个带有 Root View Controller A 的导航 Controller ,我需要呈现一个 View Controller B,我可以使用以下两种方式之一: self.naviga
我正在尝试在 viewDidLoad 中使用 presentViewController:animated:completion: (iOS 7) 以模态方式呈现 View Controller ,但
我以编程方式在 iOS Swift 项目中拥有多个 View Controller 。我没有 Storyboard,如果可能的话,我想避免使用它们。有没有办法切换到另一个 viewcontroller
调用[self presentViewController]在 UIAlertController 的实例上立即加载警报。有没有办法延迟它的呈现? [self presentViewControlle
这个问题在这里已经有了答案: presentViewController and displaying navigation bar (12 个回答) 5年前关闭。 您好,我使用此代码仅使用代码而无需
我有这段代码,用于显示警报: func arraysize() -> [Int]? { let title = "Your file is empty" let message = "
我正在尝试登录 GameCenter 我的应用程序。我收到错误: Value of type 'GameScene' has no member 'presentViewController' whe
我在 iOS 6 中使用过这段代码,我可以在主视图中间呈现另一个 View 。但是,当我在 iOS 7 中运行时,呈现的 View 的原点始终位于 0,0。我该怎么办? rect= CGRectMak
我正在 ios 4.3 中使用 [selfpresentModalViewController:headanimated:NO]; 并寻找 ios5 及更高版本的替代方案。我更喜欢使用适用于所有 iO
我有一个名为 SecondViewController 的 UIViewController,它使用 UIImagePickerController 加载照片库。当我选择一张照片时,它应该显示另一个名
我有一个应用程序,它有一个选项卡栏,它出现在大多数 ViewControllers 中。问题是它没有显示在我通过这段代码呈现的 viewController 中。 UINavigationContro
在我的 swift 应用程序中,我试图让点击按钮切换 View Controller 。这是我正在使用的代码: presentViewController(pythTheoremViewControl
作为我更新我的应用程序以用 presentViewController 替换已弃用的 presentModalViewController 的一部分,我做了一些测试。我的发现令人不安。尽管 prese
我的 iOS 应用程序有一个欢迎屏幕(不要与默认 View 混淆)。 View Controller 使用 NSXMLParser 下载并解析 XML 文件。当它完成它的任务时,它会使一个按钮可见,单
我是 Swift 的新手,为此苦苦挣扎了一段时间。 我正在尝试根据登录状态将用户重定向到“登录” View Controller 或“主页” View Controller 。 “Home”viewc
这是我在这里的第一个问题,所以它可能不是最好的格式。 在我的应用程序中,我想显示下一个屏幕,这个屏幕单独运行时工作正常,所以这里应该没有问题。我正在使用以下代码进行转换 let dataViewCon
我实际上正在与键盘作斗争!我有一个像这样呈现的 viewController : self.present(viewController, animated: true, completion: ni
我用 Storyboard制作了一个单 View 项目,添加了几个 View Controller 。初始 View Controller 有一个简单的按钮来显示另一个 View Controller
我需要用 UIViewAnimationOptionCurveEaseIn 动画呈现 View Controller ,其中源 Controller 从 1 alpha 消失到 0,目标 Contro
我一直在寻找我的问题的解决方案,但其中大部分对我来说都是无用的,因为几乎所有这些都是关于在 IB 中犯下的错误,我没有在这个项目中使用它。重点: 我有一个使用 Unity 生成的 XCode 项目,我
我是一名优秀的程序员,十分优秀!