MBProgressHUD different load styles - swift

I am having some issues to get MBProgressHUDModeDeterminateHorizontalBar style to work
Haven't found much around on Swift.
I've tried so far to create an object passing the MBProgressHUDModeDeterminateHorizontalBar as type or attribute it as a mode to an existing HUB object or add an int to the mode... but nothing seems to work.
let spinningActivity = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
spinningActivity.labelText = "Loading"
spinningActivity.detailsLabelText = "Please got get some coffee"

You need to change MBProgressHUD mode. See code bellow.
spinningActivity.mode = .DeterminateHorizontalBar
And update your loading progress:
spinningActivity.progress = /*Your loading progress*/
Hope that help!

Related

Ionic show ion-refresher programmatically

i want to display the ion-refresher programmatically. e.g on the first page load i load the data and want to show the ion-refresher. i've not found any build in function only _beginRefresh. this function will fire the refresher, however it will not set the style attribute TOP on the refresher element. therefore it is hidden behind the NAV.
currently i've created a dirty workaround.
let scrollcontent = document.getElementsByClassName('ion-page')[0].getElementsByTagName('ion-content')[0].getElementsByClassName('scroll-content')[0]
let rect = scrollcontent.getBoundingClientRect()
document.getElementById('refresher').style.top = rect.top.toString() + 'px'
this.myRefresher._beginRefresh()
i'm wondering if there is a better aproach.
thanks
ok i've found a better approach...
#ViewChild(Content) ContentDashboard: Content;
this.RefresherDashboard._top = this.ContentDashboard.contentTop.toString() + 'px'
this.RefresherDashboard._beginRefresh()

Does SwiftyJson make parsing swift json faster?

I've recently made a weather that gets data from open weather map, but it takes forever for the parsed data to show up on the screen...
With code like this:
let tempF = jsonResult["tempFahrenheit"]
I know the data is fast because I watch the url result show up immediately in the console, so would swiftyjson speed up displaying data on the screen? Is there a swiftyjson for Swift 3??
The code you have posted doesn't appear to update any UI element on the screen.
If there is another place where you are updating the UI with something like
mylabel.text = someVariable
and the UI is still laggy, it maybe because you have not wrapped the UI
change in the main thread.
The correct way to do the update above would be
DispatchQueue.main.async { mylabel.text = someVariable }
Call API> Get Response> Parse Data > Update UI [It should be in main queue]
Write your UI update related code in main queue like below ...
DispatchQueue.main.async {
textFiled.text = yourText
imageview.image = yourImage
.......
}

iOS 10 app crashes when trying to save image to photo library

I'm trying to save an image to the photo library in Swift 3 (I'm working with Xcode 8).
ViewController Code:
func shareImage(image: UIImage) {
let items = [image]
var activityVC: UIActivityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
let excludeActivities: [UIActivityType] = [UIActivityType.airDrop,
UIActivityType.assignToContact,
UIActivityType.addToReadingList,
UIActivityType.copyToPasteboard]
activityVC.excludedActivityTypes = excludeActivities
self.present(activityVC, animated: true, completion: nil)
}
When I run the application, and click on the button to take the screenshot (converting it to image, ..., that's all working perfectly), the app asks for permission to access the photo library, I tap the "OK" button, and then the app crashes. The image is not saved in the photo library.
The only clue I get from Xcode is the following:
2016-09-28 11:24:27.216043 Ajax Kids[4143:1545362] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Media/PhotoData/Photos.sqlite?readonly_shm=1 options:{
NSPersistentStoreFileProtectionKey = NSFileProtectionCompleteUntilFirstUserAuthentication;
NSReadOnlyPersistentStoreOption = 1;
NSSQLitePersistWALOption = 1;
NSSQLitePragmasOption = {
"journal_mode" = WAL;
};
} ... returned error Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Failed to access file: 1} with userInfo dictionary {
reason = "Failed to access file: 1";
}
2016-09-28 11:24:27.216433 Ajax Kids[4143:1545362] [Migration] Unexpected error opening persistent store <private>, cannot attempt migration <private>)
2016-09-28 11:24:27.216568 Ajax Kids[4143:1545362] [Migration] Failed to open store <private>. Requires update via assetsd (256: <private>)
Does anyone have any idea how to fix this?
Thanks in advance!
UPDATE
Sharing the image on Social Media works fine, so the problem is specified to saving the image in the photo library.
Add new records in your new InfoPlist.strings file.
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME)</string>
UPD: iOS 11 key
On iOS 11, there is a new property called NSPhotoLibraryAddUsageDescription, similar to NSPhotoLibraryUsageDescription. See https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
Try to force request permissions like this:
PHPhotoLibrary.requestAuthorization { status in
if status == .authorized {
//do things
}
}
do not forget import Photos. Hope this helps.
I found the culprit in my particular case. We are using Leanplum for analytics and push notifications. The Leanplum.syncResourcesAsync method was causing the opening of the photo library to crash. It took a couple of days to find as I wasn't aware Leanplum was doing anything to hook into a user's photo library... which in itself is concerning.
We weren't using the functionality this particular method brings, so were able to just remove the method call and the photo library stopped crashing.

How to setup printing in cocoa, swift?

I have made printing functionality for custom NSView of NSPopover by the assigning the following action to button for this NSView in mainController:
#IBOutlet var plasmidMapIBOutlet: PlasmidMapView!
#IBAction func actionPrintfMap(sender: AnyObject)
{
plasmidMapIBOutlet.print(sender)
}
It is working, but the print window has no option for Paper Size and Orientation, see screenshot below.
What should I do to get these options in the print window?
And, how to make the NSView fitting to the printable area? Now it is not fitting.
I have figured out some moments, but not completely. So, I can setup the printing by the following code
#IBAction func actionPrintMap(sender: AnyObject)
{
let printInfo = NSPrintInfo.sharedPrintInfo()
let operation: NSPrintOperation = NSPrintOperation(view: plasmidMapIBOutlet, printInfo: printInfo)
operation.printPanel.options = NSPrintPanelOptions.ShowsPaperSize
operation.printPanel.options = NSPrintPanelOptions.ShowsOrientation
operation.runOperation()
//plasmidMapIBOutlet.print(sender)
}
But, I still have problem. From the code above I can get only orientation (the last, ShowsOrientation), but not both PaperSize and Orientation. How can I manage both ShowsPaperSize and ShowsOrientation?
Finally I have found the answer which is simple to write but it is not really obvious from apple documentation.
operation.printPanel.options.insert(NSPrintPanelOptions.showsPaperSize)
operation.printPanel.options.insert(NSPrintPanelOptions.showsOrientation)
The problem in the code originally posted is that options is being assigned twice, so the first value assigned, ShowsPaperSize is overwritten by the value ShowsOrientation. That's why you only see the ShowsOrientation option in the dialog.
By using multiple insert operations, you are adding options rather than overwriting each time. You can also do it this way which I think reads better:
operation.printPanel.options.insert([.showsPaperSize, .showsOrientation])
And finally, it also works to "set" the options, and by supplying the existing options as the first array value, you achieve the affect of appending:
operation.printPanel.options = [
operation.printPanel.options,
.showsPaperSize,
.showsOrientation
]
(The first array element operation.printPanel.options means that the old options are supplied in the list of new options.)

Route calculation based on GPX File

I'm stuck with a navigation issue while using a GPX file to create a route navigation (turn by turn)
My GPX file parsing seems to work since I've managed to build a CLLocation Array.
The problem is that nothing shows up on my Map view. I have no routing delegate callback neither ( with the event :didFinishRouteCalculationWithInfo)
Here is my code :
let path: String = NSBundle.mainBundle().pathForResource(fileName, ofType: "gpx")!
do {
let root: SKGPSFileElement = try SKGPSFilesService.sharedInstance().loadFileAtPath(path)
let locationArray = SKGPSFilesService.sharedInstance().locationsForElement(root)
let route = SKRouteSettings()
route.shouldBeRendered = true
route.requestAdvices = true
SKRoutingService.sharedInstance().calculateRouteWithSettings(route, customLocations: locationArray)
// I also tried to read directly my SKGPSFileElement :
//SKRoutingService.sharedInstance().calculateRouteWithSettings(route, GPSFileElement: root)
} catch {
}
I tried to get some help with the Swift Skobbler Demo but they also have the issue ... (When selecting the Berlin GPX track for instance, no track appears)
Thank you in advance, I'm desperate :'( !
Okay, once again the demo project missed some lines ...
I only had to add these lines to make it work :
SKRoutingService.sharedInstance().navigationDelegate = self
SKRoutingService.sharedInstance().routingDelegate = self
SKRoutingService.sharedInstance().mapView = map
Hope it could help someone :)