【问题标题】:NSInvalidArgumentException on call GPPURLHandler调用 GPPURLHandler 时出现 NSInvalidArgumentException
【发布时间】:2015-01-14 18:42:56
【问题描述】:

我在尝试登录 Google Plus 时遇到问题,在返回应用程序时发送我的用户名和密码后我的应用程序崩溃。

错误发生在这一行:

BOOL openURL(id self, SEL _cmd, UIApplication* application, NSURL* url, NSString* sourceApplication, id annotation){
     [GPPURLHandler handleURL:url sourceApplication:@"com.google.chrome.ios" annotation:nil];
}
//...

我进入设备控制台:

: *** 由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'无法创建 NSPersistentStoreCoordinator 与 nil 模型'

然后使用打印在控制台中的 url 我尝试:

NSURL *fixedURL = [NSURL URLWithString:@"com.domain.xxxxxx:/oauth2callback?state=75029341&code=4/hy789ysdfhfRA8cuIeHbO0fP3p1oXcFeCnYJe--vZgc.klaHKD1A8zws76f7678df6782M1BcwvNlQI&authuser=0&num_sessions=1&prompt=consent&session_state=dca3e8a678sdf678a6f7d880e02bcf5155e5822c038..5f88"];

[GPPURLHandler handleURL:fixedURL sourceApplication:@"com.google.chrome.ios" annotation:nil];
//...

使用这些代码没有任何反应

那我试试:

 NSString *urlString =[NSMutableString stringWithFormat:@"%@:/oauth2callback?%@", [url scheme],[url query]];
 NSURL *fixedURL = [NSURL URLWithString:urlString];
//...

并得到第一个错误。

在属性列表键中

<key>CFBundleURLTypes</key>
   <array>
      <dict>
         <key>CFBundleURLName</key>
         <string>com.domain.xxxxxx</string>
         <key>CFBundleURLSchemes</key>
         <array>
            <string>com.domain.xxxxxx</string>
         </array>
         <key>CFBundleURLTypes</key>
         <string>Editor</string>
      </dict>
   </array>
   <key>GPGApplicationID</key>
   <string>123123123-0fnaerghgic4er3g9cmn045daasl0u1u.apps.googleusercontent.com</string>

我做错了什么?

【问题讨论】:

    标签: ios google-plus google-play-services


    【解决方案1】:

    我不确定您为什么要为此方法制造参数或尝试调用它的位置。您的UIApplicationDelegate 附有@optional 响应者:

    - (BOOL)application:(UIApplication *)application openURL:(NSURL*)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    

    GPPURLHandler 的用例将在此处调用(当注册的 URL 方案被激活时,它由操作系统调用到您的应用程序)。这将进入您的 UIApplicationDelegate 实施:

    - (BOOL)application:(UIApplication *)application openURL:(NSURL*)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
      return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
    }
    

    【讨论】:

    • 我有一个覆盖 openURL...我的应用程序不是原生 iOS 应用程序,因此我无法直接访问 UIApplicationDelegate 。
    • 如果您无权访问UIApplicationDelegate,那么您将无法响应操作系统将您的应用程序告诉openURL:.........跨度>
    • 我有“间接访问权限”,我正在覆盖 UIApplicationDelegate 中的 openURL。
    • 我很困惑。 UIApplicationDelegate@protocol。您不会覆盖这些函数;你实现它们。在UIApplicationDelegate 的实现中,使用我在上面发布的代码。
    • 我创建了现有委托的自定义子类并覆盖了委托函数 openURL
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多