Foundation symbol not found in Xcode 9 beta 4? - ios

I just switched from Xcode 9 beta 3 to beta 4 the other day, and now I get the following error when I use the OAuthSwift library to connect to Discogs.com. It doesn't seem to be a problem on either OAuthSwift or Discogs' part, though, because the error is:
dyld: lazy symbol binding failed: Symbol not found: __T0SS10FoundationE9substringS2S13CharacterViewV5IndexV2to_tF
Referenced from: /Users/nrith/Library/Developer/CoreSimulator/Devices/<blah-blah-blah>.app/Immediate.app/Frameworks/OAuthSwift.framework/OAuthSwift
Expected in: /Users/nrith/Library/Developer/CoreSimulator/Devices/<blah-blah-blah>.app/Frameworks/libswiftFoundation.dylib
It looks like something to file a radar against, but before doing that, I just wanted to see whether anyone else has come across this.
The OAuthSwift library call that's failing on line 151 of OAuthSwiftCredential:
open func authorizationHeader(method: OAuthSwiftHTTPRequest.Method, url: URL, parameters: OAuthSwift.Parameters, body: Data? = nil) -> String {
let timestamp = String(Int64(Date().timeIntervalSince1970))
let nonce = OAuthSwiftCredential.generateNonce()
return self.authorizationHeader(method: method, url: url, parameters: parameters, body: body, timestamp: timestamp, nonce: nonce)
}
open class func generateNonce() -> String {
let uuidString = UUID().uuidString
return uuidString.substring(to: 8)
}
Specifically, the uuidString.substring(to: 8) is failing.
Here's the relevant info from the stack (note that the generateNonce() method has been inlined):

Related

Apple Pay without Stripe iOS SDK

I've been using Stripe iOS SDK for a while now and everything is clear regarding the implementation. Since our app is going to support App Clips on iOS 14, we are reducing the binary size and therefore decided to remove Stripe iOS SDK as well.
So my question here is if I can somehow send payment requests via the API and omitting the Stripe SDK altogether?
p.s.: It looks like I need to implement the /tokens endpoint passing the card data. Is there any example of the request to be made?
I've managed to solve this situation and here is the solution if anyone is interested. Here are the steps to make this happen:
Prepare a request model
import Foundation
import PassKit
struct StripeTokenRequest: Encodable {
let pkToken: String
let card: Card
let pkTokenInstrumentName: String?
let pkTokenPaymentNetwork: String?
let pkTokenTransactionId: String?
init?(payment: PKPayment) {
guard let paymentString = String(data: payment.token.paymentData, encoding: .utf8) else { return nil }
pkToken = paymentString
card = .init(contact: payment.billingContact)
pkTokenInstrumentName = payment.token.paymentMethod.displayName
pkTokenPaymentNetwork = payment.token.paymentMethod.network.map { $0.rawValue }
pkTokenTransactionId = payment.token.transactionIdentifier
}
}
extension StripeTokenRequest {
struct Card: Encodable {
let name: String?
let addressLine1: String?
let addressCity: String?
let addressState: String?
let addressZip: String?
let addressCountry: String?
init(contact: PKContact?) {
name = contact?.name.map { PersonNameComponentsFormatter.localizedString(from: $0, style: .default, options: []) }
addressLine1 = contact?.postalAddress?.street
addressCity = contact?.postalAddress?.city
addressState = contact?.postalAddress?.state
addressZip = contact?.postalAddress?.postalCode
addressCountry = contact?.postalAddress?.isoCountryCode.uppercased()
}
}
}
Use JSONEncoder and set keyEncodingStrategy to .convertToSnakeCase.
Create a POST request against https://api.stripe.com/v1/tokens endpoint where you need to url encode parameters. If you are using Alamofire, you need to set encoding to URLEncoding.default.
Parse response. I use JSONDecoder with the following model:
import Foundation
struct StripeTokenResponse: Decodable {
let id: String
}
Create a payment
StripeTokenResponse.id is the thing you need to pass to the backend where the payment will be processed. This is the same step as you'll do when using the SDK.
You can check Strip checkout, it allows you to present a payment page in web format without any Stripe SDK on the client side.

Firebase DynamicLink Url returning jSON serialize error. iOS

Xcode version: 10.1
Firebase SDK version: 6.0.0
Firebase Component: Firebase/DynamicLinks
Component version: 4.0.0
Hi, I am stuck at a point when dealing with Dynamic linking, all is good when making a link, but i am getting error on the link which is like this
<ExceptionMessage>
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.
</ExceptionMessage>
<InnerException>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Object reference not set to an instance of an object.
</ExceptionMessage>
<ExceptionType>System.NullReferenceException</ExceptionType>
and link which is generated https://marcoapp.page.link/T4Ye is here which is having issue.
i know that is error where someone would say it's from backend , but no same things worked before and even Android level of application is still working fine with same parameters. And i didn't get what is wrong thing i am sending or not sending which is causing this issue. Below mentioned is the code.
guard let components: DynamicLinkComponents = DynamicLinkComponents(link: urlLink, domainURIPrefix: "https://marcoapp.page.link") else {
return ""
}
in here urlLink = https://marcotest.azurewebsites.net/api/Groups/(Int)
func createDynamicLink() {
let domain = "yourProject.page.link"
let link = URL(string: "https://facebook.com")
let referralLink = DynamicLinkComponents(link: link!, domain: domain)
referralLink.iOSParameters = DynamicLinkIOSParameters(bundleID: “set_app_bundleID")
referralLink.iOSParameters?.appStoreID = "app_store_id"
referralLink.androidParameters = DynamicLinkAndroidParameters(packageName: "set_app_bundleID")
guard let longUrl = referralLink.url?.absoluteString else {
return
}
print(longUrl)
}
Make sure you have already created domain in firebase account in Dynamic links section then only you can use let domain = "yourProject.page.link"
https://imgur.com/a/Fg5qHyV

How to access JSON response in Swift using AWS API Gateway-generated iOS SDK

I have a working REST API based on this API Gateway tutorial. I'm able to successfully invoke it via the test functionality of the AWS Console; and I'm able to successfully invoke it via my simple iOS Swift 4.2 Xcode application using the iPhone XR simulator.
I know it's working via a real, live external call because I can see the Cloudwatch logs which always register a 200 response and is sending the results back to the Client.
My problem is really in understanding the Swift code, and I'm hoping that a Swift expert can help me understand how to unpack result in the code below.
Here's my code in ViewController.swift for invoking the REST API and attempting to print result to the console:
#IBAction func userInvokeApi(_ sender: UIButton) {
print("You clicked invoke api...")
let client = SVTLambdaGateClient.default()
client.calcGet(operand2: "3", _operator: "+", operand1: "5").continueWith{ (task: AWSTask?) -> AnyObject? in
if let error = task?.error {
print("Error occurred: \(error)")
return nil
}
if let result = task?.result {
// Do something with result
print("The result is... \(result)")
}
return nil
}
}
As pointed out in the comments below, I'm getting the following result because it's printing out the address of the object:
You clicked invoke api...
The result is... <AmplifyRestApiTest.Empty: 0x600002020770> {
}
(where AmplifyRestApiTest is the name of my Xcode project.)
UPDATE When I set a breakpoint on the print statement, this is what I see in the Debug pane:
UPDATE 2
When I type task?.result there are two viable properties as per this answer from the Amplify team: error and result. So, since my API responds successfully I am assuming I just don't know how to view result.
Can someone help me understand what steps I must take to access members of this class object?
Here is the corresponding method in the API Gateway-generated iOS Swift SDK code:
/*
#param operand2
#param _operator
#param operand1
return type: Empty
*/
public func calcGet(operand2: String, _operator: String, operand1: String) -> AWSTask<Empty> {
let headerParameters = [
"Content-Type": "application/json",
"Accept": "application/json",
]
var queryParameters:[String:Any] = [:]
queryParameters["operand2"] = operand2
queryParameters["operator"] = _operator
queryParameters["operand1"] = operand1
let pathParameters:[String:Any] = [:]
return self.invokeHTTPRequest("GET", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: Empty.self) as! AWSTask<Empty>
}
I'm fairly certain this return type of Empty refers to the Empty model defined for the REST API as shown in the screenshot below. I think it's "empty" because the API doesn't alter the response from the Lambda function back to the Client. So, it's all pass-through. Indeed, the tutorial explains that the other models -- Output and Result -- are not used because it "relies on the passthrough behavior and does not use this model."
Any thoughts?

I have upgraded my app from swift 2.3 to swift 3.0, i am facing a big issue in resolving Alamofire issues regarding upload request

I am getting following error on returning value
//Cannot invoke 'upload' with an argument list of type '(URLRequestConvertible, data: NSData)' Pods are updated and i have updated the code as well still facing the same error.Updated image
if !Reachability.isConnectedToNetwork() {
print("Request:\(baseURL + self.rawValue) \nParams:\(aParams) \n \(imageFileName):[FILE]")
let alert = SwAlert.generate(Global.Constants.APP_DISPLAY_NAME, message: Global.ConstantsMessages.connectionFailedMsg )
alert.addAction("Ok", completion: { (resultObject) -> Void in
})
alert.show()
return nil
}else {
print("Request:\(baseURL + self.rawValue) \nParams:\(aParams) \n \(imageFileName):[FILE]")
let urlRequest = self.urlRequestWithComponents(baseURL + self.rawValue, parameters: aParams, imageData: imageData, imageFileName:imageFileName )
return Alamofire.upload(data:urlRequest.1, to: urlRequest.0)
}
Correct syntax for alamofire upload request in swift 3 is -
Alamofire.upload(data: Data, to: URLConvertible)
You are just using the parameters wrongly..

Linking error in unit test using URLRequestConvertible

I have a weird problem writing a simple unit test (Xcode 7.2) for a very simple function which makes sure a parameter is added to a URL:
func appendToken(token: String, toRequest request: URLRequestConvertible) throws -> URLRequestConvertible {
var error: NSError?
let modifiedRequest: NSMutableURLRequest
(modifiedRequest, error) = Alamofire.ParameterEncoding.URL.encode(request, parameters: ["token": self.token])
guard error == nil else {
// TODO: handle error
throw error!
}
return modifiedRequest
}
The unit test is like this:
func testTokenAddition() {
let token = "ABCD12345"
let client = MyClass(token: token)
let originalRequest = NSURLRequest(URL: NSURL(string:"http://localhost")!)
do {
let modifiedRequest = try client.appendToken(token, toRequest: originalRequest).URLRequest
XCTAssertTrue(modifiedRequest.URLRequest.URLString.hasSuffix("token=\(token)"))
} catch {
XCTFail()
print(error)
}
}
Obviously this is a very simple test on which I want to build upon (so please don't focus on the actual assertion). But when I try to run the test, I get this linking error:
Undefined symbols for architecture x86_64:
"protocol witness table for __ObjC.NSURLRequest : Alamofire.URLRequestConvertible in Alamofire", referenced from:
SDKitTests.SDKitTests.testTokenAddition (SDKitTests.SDKitTests)() -> () in SDKitTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The function works when I run it from a normal target, so the problem is in the test function, but I'm not clear on how I should be calling it, I run the same code in a non-test class and there was no problem, so I'm a bit puzzled by this. Also the error message is a bit cryptic, from what I've Googled, a witness table is kind of like a vtable for protocols. But I haven't messed with that, the extension to NSMutableURLRequest is implemented in Alamofire, and I'm just using it.
What am I doing wrong? What do I need to do to fix it?
Ensure the Alamofire library is linked with your test target.
You may also need to remove inherit! :search_paths from the test target.

Resources