This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function creates the required URLRequestConvertible and NSData we need to use Alamofire.upload | |
func urlRequestComponentsWithParams(urlString:String, parameter: [String: AnyObject], imageData:[NSData], inputName: String) -> (URLRequestConvertible, NSData) { | |
// create url request to send | |
let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: urlString)!) | |
mutableURLRequest.HTTPMethod = Alamofire.Method.PUT.rawValue | |
let boundaryConstant = "FileUploader-boundary-\(arc4random())-\(arc4random())"; | |
let contentType = "multipart/form-data;boundary="+boundaryConstant | |
mutableURLRequest.setValue(contentType, forHTTPHeaderField: "Content-Type") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ARN Endpoint | |
// For Amazon SNS | |
NSString *myARN = @"arn:aws:sns:ap-southeast-1:570761336625:app/APNS_SANDBOX/Airportthai"; | |
AWSSNSCreatePlatformEndpointInput *platformEndpointRequest = [AWSSNSCreatePlatformEndpointInput new]; | |
[platformEndpointRequest setCustomUserData:@"custom user data เช่นระบบ iOS version, Device Version อะไรก็ได้"]; | |
[platformEndpointRequest setToken:[self deviceTokenAsString:deviceToken]]; //แปลง device token ให้เป็น string ก่อนนะ | |
[platformEndpointRequest setPlatformApplicationArn:myARN]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AWS SNS Config | |
// Credential | |
AWSStaticCredentialsProvider *credential = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:@"YOUR_AMAZON_ACCESSKEY" | |
secretKey:@"YOUR_AMAZON_SECERT"]; | |
// Config region | |
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionAPSoutheast1 | |
credentialsProvider:credential]; | |
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
let jsonString = "{\"username\" : \"thunderbird\", \"password\" : \"tb00110\"}" | |
func jsonDecodeString(json: String) -> Dictionary<String, AnyObject>? { | |
let json:NSData = jsonString.dataUsingEncoding(NSUTF8StringEncoding)! | |
do { | |
return try NSJSONSerialization.JSONObjectWithData(json, options: NSJSONReadingOptions.MutableContainers) as? Dictionary<String, AnyObject> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)testAsynchronousURLConnection { | |
// Create request | |
NSURL *URL = [NSURL URLWithString:@"http://httpbin.org/get"]; | |
NSString *description = [NSString stringWithFormat:@"GET %@", URL]; | |
XCTestExpectation *expectation = [self expectationWithDescription:description]; | |
NSURLSession *session = [NSURLSession sharedSession]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func abbreviateNumber(num: NSNumber) -> String { | |
// less than 1000, no abbreviation | |
if num < 1000 { | |
return "\(num)" | |
} | |
// less than 1 million, abbreviate to thousands | |
if num < 1000000 { | |
var n = Double(num); | |
n = Double( floor(n/100)/10 ) |
NewerOlder