AWS 分析 - swift 3 - iOS?

AWS analytics - swift 3 - iOS?

我正在尝试将移动分析与 Swift 3 一起使用,目前通过 CocoaPods 拥有 AWSCore 2.5.9 和 AWSMobileAnalytics 2.5.9,但我无法记录任何事件。我的合作伙伴使用 Android 成功记录了与我正在使用的相同 CognitoIdentityPoolId 的事件,并且我还确认它附加了 AmazonMobileAnalyticsFullAccess 策略。

我的 AppDelegate 中有以下代码 didFinishLaunchingWithOptions

  let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.USWest2,
                  identityPoolId:"us-west-2:theRestOfMyID")

      let configuration = AWSServiceConfiguration(region:.USWest2,
                                                  credentialsProvider:credentialsProvider)

      AWSServiceManager.default().defaultServiceConfiguration = configuration

      let analyticsConf = AWSMobileAnalyticsConfiguration.init()

      analyticsConf.serviceConfiguration = AWSServiceManager.default().defaultServiceConfiguration

      _ = AWSMobileAnalytics.init(forAppId: "MyMobileAnalyticsAppId", configuration: analyticsConf)

这导致控制台输出:

2017-07-20 16:39:53:875 test2[7288:125553] Mobile Analytics SDK(2.0-alpha) Initialization successfully completed.
2017-07-20 16:39:53:875 test2[7288:125635] 
==========Batch Object==========
{"attributes":{"_session.id":"82e879d9-C9E6D9C7-20170720-233953870","ver":"v2.0","_session.startTime":"2017-07-20T23:39:53.872Z"},"event_type":"_session.start","timestamp":"2017-07-20T23:39:53.873Z"}
2017-07-20 16:39:53:876 test2[7288:125635] Event: '_sess...' recorded to local filestore

我有一个记录事件然后尝试提交事件的按钮:

 let eventClient = AWSMobileAnalytics(forAppId: "MyMobileAnalyticsAppId").eventClient

      guard let client = eventClient else {
         print("Error creating AMA event client")
         return
      }
      guard let event = client.createEvent(withEventType: "test_50_logIn") else {
         print("Error creating AMA event")
         return
      }
      event.addAttribute("username", forKey: "sample")
      event.addAttribute("device", forKey: "ios")
      client.record(event)

      client.submitEvents()

但是,submitEvents 总是触发以下错误,这两天我一直无法解决。因此,我无法记录单个 iOS 事件。

2017-07-20 16:46:01:736 test2[7566:129412] Unable to successfully deliver events to server. Error Message:Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={NSUnderlyingError=0x6080002438a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, NSErrorFailingURLStringKey=https://mobileanalytics.us-west-2.amazonaws.com/2014-06-05/events, NSErrorFailingURLKey=https://mobileanalytics.us-west-2.amazonaws.com/2014-06-05/events, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSLocalizedDescription=A server with the specified hostname could not be found.}

我在集成指南下看不到其他步骤,如果 ID 在 android 集成中工作得很好,有人知道问题出在哪里吗?谢谢!

移动分析在美国西部 (Docs) 不可用。

Q: What AWS Regions is the Amazon Mobile Analytics service available in?

Currently, Amazon Mobile Analytics is available in the AWS US East (N. Virginia) Region.

您只需更改 AWSServiceConfiguration 中的区域:

let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialsProvider)
let analyticsConfiguration = AWSMobileAnalyticsConfiguration()
analyticsConfiguration.serviceConfiguration = serviceConfiguration
_ = AWSMobileAnalytics(forAppId: "MyMobileAnalyticsAppId", configuration: analyticsConfiguration)

端点:
https://mobileanalytics.us-west-2.amazonaws.com => 不起作用
https://mobileanalytics.us-east-1.amazonaws.com/ => 做