2017-08-17 88 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 –

相關問題