I have some major issues with the MKSnapshotter when testing my 'Watch Application' / iOS app watch extension on a real iPhone connected to a Apple Watch!
Inside one of my Interface Controllers I call the following function:
func createMapSnapshot(){
//Snapshotter for overview image
self.options = MKMapSnapshotOptions()
self.options!.region = getEndRegion()
self.snapshotter = MKMapSnapshotter(options: options!)
snapshotter!.startWithCompletionHandler() {snapshot, error in
dispatch_async(dispatch_get_main_queue()) {
var finalImage = self.drawEndRun(snapshot.image, snapshot: snapshot)
self.mapImage.setImage(finalImage)
}
}
}
This should create an image of the map and fill my WKInterfaceImage with it. As soon as I create the Image my memory jumps from about 3 MB to 20 MB and stays there even if i set options = nil and snapshotter = nil. Also I get the following message printed on the console:
WatchKit Extension[9548:2529231] BSXPCMessage received error for message: Connection interrupted
But here comes the worst part: As soon as I want to create another snapshot my Watch App crashes due to a memory error! I assume that this happens because the snapshotter won't free the memory after allocating it... How can I do that manually or does someone have another idea?
It has nothing to do with the getEndRegion() function! I also tested it with the default snapshotter without options -> same result!
If I test the app in the simulator everything works fine!
UPDATE:
I searched the documentation of MKMapSnapshotter and it says, that it can only deliver a snapshot if the app is in the foreground, thus it can't be rendered from the main Application and the memory allocated to the iOS watch extension is too low, so is there any other way??