2016-01-29 16 views
16

Tôi đang làm việc để kết nối ứng dụng Parse với Máy chủ phân tích cú pháp Node.js của tôi bằng ngôn ngữ Swift. Trong tài liệu của Parse, tôi có thể nhìn thấy đoạn mã này:Làm thế nào để kết nối ứng dụng Swift với máy chủ Parse của tôi?

[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) { 
    ... 

    configuration.applicationId = @"YOUR_APP_ID"; 
    configuration.clientKey = @"YOUR_APP_CLIENT_KEY"; 
    configuration.server = @"http://localhost:1337/parse"; 

    ... 

}]]; 

Và kể từ khi tôi sử dụng ngôn ngữ Swift, đây là cấu hình của tôi cho đến bây giờ:

// Initialize Parse. 
Parse.setApplicationId("APP_ID", clientKey: "CLIENT_KEY") 

Nhưng làm thế nào tôi có thể xác định máy chủ như trong mã Objective-C?

Cảm ơn!

+2

FYI - Parse.com sắp tắt. Bạn nên tìm một giải pháp khác trước khi hoàn thành ứng dụng của mình. – rmaddy

+3

@rmaddy Đó là lý do chính xác tại sao tôi đang cố di chuyển sang Máy chủ "Tự lưu trữ" Parse ;-) – fraxool

+1

Ah. Có lẽ cần phải có một thẻ mới cho điều đó. – rmaddy

Trả lời

27

Tìm thấy câu trả lời của bản thân mình, đây là làm thế nào để thiết lập một cấu hình (bao gồm URL server) với Swift:

let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in 
    ParseMutableClientConfiguration.applicationId = "APP_ID" 
    ParseMutableClientConfiguration.clientKey = "CLIENT_KEY" 
    ParseMutableClientConfiguration.server = "http://your_server.com:1337/parse" 
}) 

Parse.initializeWithConfiguration(parseConfiguration) 

Hy vọng nó sẽ giúp người khác.

3

Parse Server bây giờ có một số tốt documentation đi và về cơ bản đề nghị giải pháp @ fraxool với một cú pháp gọn gàng chút:

let configuration = ParseClientConfiguration { 
    $0.applicationId = "YOUR_APP_ID" 
    $0.clientKey = "" 
    $0.server = "http://localhost:1337/parse" 
} 
Parse.initializeWithConfiguration(configuration) 
2

Chỉ cần thêm câu trả lời với Swift 3:

let configuration = ParseClientConfiguration { 
     $0.applicationId = "YOUR_APP_ID" 
     $0.clientKey = "" 
     $0.server = "http://localhost:1337/parse" 
    } 
    Parse.initialize(with: configuration) 
0

// Đặt ID ứng dụng

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

     let configuration = ParseClientConfiguration { 
      $0.applicationId = PARSE_APP_KEY 
      $0.clientKey = PARSE_CLIENT_KEY 
      $0.server = "https://example.com" 
     } 
} 
Các vấn đề liên quan