2017-08-17 46 views
0

我在使用Swift 3.0编写的应用程序中使用AWSNS。我在我的注册功能中的一行代码中遇到这个Can't Call Value of non Function Type 'AWSSNS'错误。无法调用非函数类型'AWSSNS'的值

以下是我的代码:

func myfunction(){ 
    initial() 
    let tkn = nd.value(forKey: "devicetoken") as! String 
    var myArn: String = myARN 

    var platformEndpointRequest = AWSSNSCreatePlatformEndpointInput() 
    platformEndpointRequest?.customUserData = "MyUserID;iPhone7" 
    platformEndpointRequest?.token = tkn 

    platformEndpointRequest?.platformApplicationArn = SNSPlatformApplicationArn 
//var snsManager.... this line below is giving error 
     var snsManager = AWSSNS()(configuration: configuration) 
     var endpt = snsManager.createPlatformEndpoint(platformEndpointRequest) 

    } 

我应该心存感激,如果有人帮助。

+0

是不是应该是'AWSSNS(配置...' – vadian

+0

让我试试这一个 –

+0

Vadian,我把它改成一个你?建议现在它说“改变配置为forKey”我不知道这是什么关键要求。看这里[IMAGE](https://ibb.co/iHCYBa) –

回答

0

它为我的作品:

let sns = AWSSNS.defaultSNS() 
let request = AWSSNSCreatePlatformEndpointInput() 
request.token = deviceTokenString 
     request.platformApplicationArn = SNSPlatformApplicationArn 
     sns.createPlatformEndpoint(request).continueWith(executor: AWSExecutor.mainThreadExecutor(), block: { (task: AWSTask!) -> AnyObject! in 
      if task.error != nil { 
       print("Error: \(task.error)") 
      } else { 
       let createEndpointResponse = task.result as! AWSSNSCreateEndpointResponse 
       print("endpointArn: \(createEndpointResponse.endpointArn)") 
       NSUserDefaults.standardUserDefaults().setObject(createEndpointResponse.endpointArn, forKey: "endpointArn") 
      } 

      return nil 
     }) 
+0

谢谢萨尔曼,我尝试过,但没有endpointArn正在生成。控制台显示此:'错误:可选(错误域= com.amazonaws.AWSSNSErrorDomain代码= 0“(空)”)' –

+0

看到这个更多的帮助: - https://github.com/awslabs/aws-sdk-ios-samples/blob/master/SNS-MobileAnalytics-Sample/Swift/Sample_SNS_MobileAnalytics/AppDelegate.swift –

相关问题