Alex
Alex

Reputation: 141

CloudKit Query works on Xcode release build, not on TestFlight

Here's my problem: my app fetches records from CloudKit fine when connected to Xcode on my phone (using a Release scheme), but when I release it on TestFlight, it won't fetch the records.

Here's my fetching function:

func allprevFacts(date: String, olddate: Int){
        act.startAnimating()
        let container = CKContainer.defaultContainer()
        let publicDB = container.publicCloudDatabase
        //let factPredicate = NSPredicate(format: "recordID = %@", CKRecordID(recordName: date))
        let factPredicate = NSPredicate(format: "date <= %@", NSDate())
        let query = CKQuery(recordType: "BirdFacts", predicate: factPredicate)
        publicDB.performQuery(query, inZoneWithID: nil) { (results, error) -> Void in
            if error != nil {
                print(error)
            }
            else {
                dispatch_async(dispatch_get_main_queue()){
                    //print(results)
                    var count = 0
                    var sortedresults = [Int]()
                    for result in results! {
                        var b = result.valueForKey("sortingDate") as! Int
                        sortedresults.append(b)
                    }
                    print(sortedresults)
                    while count < sortedresults.count {
                        if sortedresults[count] <= olddate {
                            sortedresults.removeAtIndex(count)
                        }
                        else {
                            count = count + 1
                        }
                    }
                    print(sortedresults)
                    while sortedresults.count > 0 {
                        var d: Int = 0
                        let a = sortedresults[sortedresults.endIndex-1]
                        print(a)
                        while d < sortedresults.count{
                            if sortedresults[d] == a {
                                sortedresults.removeAtIndex(d)
                                self.birdFacts.append(results![d])
                                self.tableFacts.reloadData()
                                self.tableFacts.hidden = false
                            }
                            d = d + 1
                            print(d)
                        }
                    }
                    self.saveFacts()
                    print("saving bird facts")
                    self.tableFacts.hidden = false
                }
            }
        }
        act.stopAnimating()
    }

Here's the iPhone console output when I launch the app (and it should run the CloudKit query):

Jun 8 09:15:06 Alexs-iPhone SpringBoard[63] : SecTrustEvaluate [leaf IssuerCommonName SubjectCommonName] Jun 8 09:15:06 Alexs-iPhone SpringBoard[63] : SecTrustEvaluate [leaf IssuerCommonName SubjectCommonName] Jun 8 09:15:06 Alexs-iPhone kernel[0] : xpcproxy[468] Container: /private/var/mobile/Containers/Data/Application/85885117-5626-4CC1-90B4-A7C14F5C9AE5 (sandbox) Jun 8 09:15:06 Alexs-iPhone com.apple.xpc.launchd[1] : assertion failed: 13F69: launchd + 116796 [9F6284CF-8A17-36CC-9DB5-85D510A21F14]: 0x3 Jun 8 09:15:07 Alexs-iPhone limitadtrackingd[463] : Lost connection from Limit Ad Tracking client. Jun 8 09:15:07 Alexs-iPhone limitadtrackingd[463] : Lost connection from Limit Ad Tracking client. Jun 8 09:15:08 Alexs-iPhone SpringBoard[63] : Application 'UIKitApplication:com.apple.AdSheetPhone[0x5386]' exited voluntarily. Jun 8 09:15:08 Alexs-iPhone UserEventAgent[26] : 94505698100: id=com.apple.AdSheetPhone pid=464, state=0 Jun 8 09:15:08 Alexs-iPhone cloudd[197] : no delegate for <__NSCFLocalDataTask: 0x103d617c0>{ taskIdentifier: 11 } { completed } (CKDQueryURLRequest requestUUID:22D6A501-9D0B-4388-8316-431100DA5BE3) in session <__NSURLSessionLocal: 0x1002ddd80> for call URLSession:task:didCompleteWithError: Jun 8 09:15:18 Alexs-iPhone assistantd[30] : tcp_connection_tls_session_error_callback_imp 13 __tcp_connection_tls_session_callback_write_block_invoke.434 error 22 Jun 8 09:15:18 Alexs-iPhone assistantd[30] : NSURLSessionStreamTask: TCPConnection read invalidated by closed connection Jun 8 09:15:18 Alexs-iPhone networkd[100] : -[NETAWDManager reportStats:metricID:] AWDServerConnection newMetricContainerWithIdentifier failed for metric 2686980, server 0x14562a930, not reporting: { "client_id" = assistantd; "establishment_cellular_fallback" = 0; "establishment_failure_error" = 0; "establishment_forced_tcp_fallback" = 0; "establishment_interface_name" = en0; "establishment_success" = 1; "establishment_syn_retransmits" = 0; "establishment_tcp_fallback" = 0; "establishment_time" = "0.05480975"; "interface_reports" = ( { "data_in_KB" = 0; "data_out_KB" = 0; "interface_name" = "pdp_ip0"; "post_connect_subflow_failure_errors" = ( ); "post_connect_tcp_fallback_count" = 0; "secondary_flow_failure_count" = 0; "secondary_flow_success_count" = 1; }, { "data_in_KB" = 5; "data_out_KB" = 2; "interface_name" = en0; "post_connect_subflow_failure_errors" = ( ); "post_connect_tcp_fallback_count" = 0; "secondary_flow_failure_count" = 0; "secondary_flow_success_count" = 0; } ); "post_connect_multi_homed" = 1; "post_connect_session_lifetime" = "42.576455291"; "post_connect_single_homed" = 0; "post_connect_subflow_attempt_count" = 2; "post_connect_subflow_max_subflow_count" = 2; "subflow_switching_count" = 0; } Jun 8 09:15:19 Alexs-iPhone SpringBoard[63] : [* error]: XPC Error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.coreduetd.knowledge was invalidated from this process." UserInfo={NSDebugDescription=The connection to service named com.apple.coreduetd.knowledge was invalidated from this process.}

I can't make head or tails of the error code, does anyone have some suggestions on what might be going wrong?

Upvotes: 2

Views: 525

Answers (1)

Edwin Vermeer
Edwin Vermeer

Reputation: 13127

When you distribute an app with TestFlight, that app will use the production container. Before you can use that app, you have to move your container into production. You can do that from the CloudKit dashboard.

Select your container. Click in the menu on 'Deployment'. Then Click on the button 'Deploy to production' and follow the instructions.

Upvotes: 4

Related Questions