Posts

Showing posts with the label ios

Swift - Firebase how to get only childs values without parent

Swift - Firebase how to get only childs values without parent In the database i has a child cities with the name of "cities" under it and each city has multiple areas contains the coordinations I went through every child under "cities" to find the closest location and got the city name using ref.child("cities").observe() : ref.child("cities").observe() for child in snapshot.children { let childSnap = child as! DataSnapshot if let dicionary = childSnap.value as? [String: AnyObject]{ var latitude1 = dicionary["latitude"] as! Double var longitude1 = dicionary["longitude"] as! Double var altitude1 = dicionary["altitude"] as! Double lets say the closest city is "city 2" and place it in a variable called selectedCity. So I repeat and add it to ref.child("cities").child(selectedCity) : ref.child("cities").child(selectedCity) ref.child("cities").child(...

Swift charts - x axis values not aligned with bars in Group bar chart

Swift charts - x axis values not aligned with bars in Group bar chart i have created the simple bar chart with the library from https://github.com/danielgindi/ios-charts still can't figure out how to aligned x axis values with grouped bars. I am using a separate class for value formatting and i have a general function for draw n number of grouped bar charts. func createGroupedBarChart(with data: ChartDataCollection) { let grpBarChartView = BarChartView() self.addSubview(grpBarChartView) self.addConstraintsWithFormat(format: "H:|-5-[v0]-5-|", views: grpBarChartView) self.addConstraintsWithFormat(format: "V:|-5-[v0]-5-|", views: grpBarChartView) grpBarChartView.noDataText = "You need to provide data for the chart." grpBarChartView.chartDescription?.text = data.chartDescription if let barGrpChartData = data.chartData as? [BarChartGrouped] { //legend let legend = grpBarChartView.legend legend.enabled...

How to get list of downloaded files from External File Directory in xamarin.forms?

How to get list of downloaded files from External File Directory in xamarin.forms? I am working in xamarin.forms. I want to download file and also want to show all the downloaded files as a list. I want to implement this feature in both android and IOS. I took reference from below link to download files. It was successfully implemented. https://forums.xamarin.com/discussion/71203/how-to-download-a-file-in-xamarin-forms-and-store-it-in-the-device-storage But Now I want to list out all the downloaded files which are available in that folder. I did not any solution for the same. For android : public void Downloaded() { CrossDownloadManager.Current.PathNameForDownloadedFile = new Func<Plugin.DownloadManager.Abstractions.IDownloadFile, string>(file => { string fileName = Android.Net.Uri.Parse(file.Url).Path.Split('/').Last(); return Path.Combine(ApplicationContext.GetExternalFilesDir(Android.OS.Environment.DirectoryDownlo...

Reference to a TableView Delegate Object within a Scene in Swift 4

Reference to a TableView Delegate Object within a Scene in Swift 4 I have a tableview in a SpriteKit scene. Using a tableview delegate method, I like to pass to another scene/ViewController, which cell was selected. There is only a single storyboard as this is entirely a SpriteKit game. //TableView inside Scene & Delegate Protocol: protocol gameSelectedDelegate { func theGameSelected(gameInt: Int) } class GamesTableView: UITableView, UITableViewDelegate,UITableViewDataSource { //Test Data var items: [String] = ["Player1", "Player2"] let defaults = UserDefaults.standard var gamesList = [Game]() var passedGame: Int? //instance of delegate var selectionDelegate: gameSelectedDelegate!` //GameScene to receive tableview data and delegate for my tableview class GamePlay: SKScene, gameSelectedDelegate { var backButton = SKLabelNode(fontNamed: "ArialRoundedMTBold") var score = SKLabelNode(fontNamed: "ArialRoundedMTBold") var passedGame = 0 //Not gett...

Sometime mac keyboard dosen't work i have to type from simulator keyboard

Image
Sometime mac keyboard dosen't work i have to type from simulator keyboard I googled it and try many options but doesn't get success i am working on two apps at a time so when i run one app. mac keyboard works but when i run another app it stop working. i have to type from simulator keyboard i tried Hardware>Keyboard>Connect Hardware Keyboard but doesn't work and sometimes it work i am able to type from mac keyboard in same case. i am using xcode 9.2. I also tried this question Not able to type in textfield in iphone simulator using Mac Keyboard? any help will appreciate Hardware>Keyboard>Connect Hardware Keyboard 2 Answers 2 If you delete the following file and restart Xcode it should work. ~/Library/Preferences/com.apple.iphonesimulator.plist Or you can try this: https://stackoverflow.com/a/47696048/413877 This worked for me Xcode 9.3: Simulator app > Quit Simulator Simu...

Is there a way to ask user for Camera access after they have already denied it on iOS?

Is there a way to ask user for Camera access after they have already denied it on iOS? I am using this code, but unfortunately it doesn't work. After a user has denied camera access, I want to ask them for permission to use the camera again the next time they try to load it (in this case it's a barcode scanner using the camera view). I always get AVAuthorizationStatusDenied and then granted always automatically returns NO even though I ask for it again in code. AVAuthorizationStatusDenied granted NO Many of my users are e-mailing me saying "my screen is black when I try to barcode scan" and it's because they have denied camera access for some reason. I want to be able to prompt them again because most likely the denial was a mistake. Is there a possible way to do this? AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if(authStatus == AVAuthorizationStatusAuthorized) { NSLog(@"%@...

How to get sleep data without healthkit in iOS 10

How to get sleep data without healthkit in iOS 10 I wants to get accurate sleep data into my iOS app without using health kit. Please provide suggestions. https://apple.news/As1Ja5ZpOSzOt--RV8NkIWQ Can you please be more specific on what you want to achieve here? because for some specific scenarios, there is no way beyond using iOS healthKit! – Karthick Ramesh Jul 2 at 5:17 @KarthickRamesh I want to display user sleep data in admin panel and i want it without health kit as it needs user permission. – Hemant Solanki Jul 2 at 5:58 1 Answer 1 No, for getting sleep data from iphone you need to use the health kit....

CGImageRef is nil?

CGImageRef is nil? I'm trying to take pictures in my app using AVFoundatin. In the didFinishProcessingPhoto block I run some code to gather the image data and create an image to show in the preview screen. Code included below: didFinishProcessingPhoto func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) { if let error = error { print("Error capturing photo: (error)") } else { let photoData = photo.fileDataRepresentation() if let currentData = photoData { let dataProvider = CGDataProvider(data: currentData as CFData) let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: CGColorRenderingIntent.defaultIntent) let image = UIImage(cgImage: cgImageRef!, scale: 1.0, orientation: self.getImageOrientation(forCamera: self.videoDeviceInput.device.position)) let containerView = PreviewPhotoC...

Disabling zooming on webview

Disabling zooming on webview I've searched around, but I couldn't find how to disable zooming in iOS. I have this in my viewDidLoad() but it doesn't do anything. viewDidLoad() webView.scrollView.isMultipleTouchEnabled = false; Any ideas? 2 Answers 2 You can disable zooming like this: webView.scalesPageToFit = NO; webView.multipleTouchEnabled = NO; I'm trying to disable zooming though, not scrolling – Sam 5 hours ago @Sam Sorry, I misread the question. – hev1 5 hours ago no worries, but isn't this Obj-C? Cause they spew errors saying: Value of type 'WKWebVi...

Connect Two ScrollView’s Together with different Content Offset Values

Connect Two ScrollView’s Together with different Content Offset Values To Scroll 2 different scrollView together, Many questions have been already answered regarding using the scrollViewDidScroll Method and passing the content offset of one scrollview to other. But My Question here is a bit different, Let’s say I have 2 ScrollView A and B both with horizontal scrolling only. When the view loads ScrollView A has contentOffSet say (x,y) and B scrollview’s content offset : (m,n). As per my understanding content Offset is the new (x,y) value while scrolling. Now I can’t pass the content Offset value of A to B here to scroll them together as they loads at different points due to content requirement.I need the exact x points displaced while scrolling in A, then may be pass it to B. I have also tried getting the velocity from pangesture of A and passing it to B, which doesn’t work smoothly. How can I achieve a smooth scrolling for both views ? Just a question why d...

Why placeholder text jump upward little when first tap searchBar?

Image
Why placeholder text jump upward little when first tap searchBar? I put a searchBar in first cell in the UITableView (not in UITableView header!) : firstCell.contentView.addSubview(searchController.searchBar) and I canceled hide navigation bar when search happened : searchController.hidesNavigationBarDuringPresentation = false and full setup searchController code in below : func setupSearchController(){ //custom Search Results Controller let folderSearchVC = FolderSearchViewController() searchController = UISearchController(searchResultsController: folderSearchVC) //cancel hide NavigationBar searchController.hidesNavigationBarDuringPresentation = false searchController.searchResultsUpdater = folderSearchVC searchBar = searchController.searchBar searchBar.placeholder = "搜索习惯组" firstCell.contentView.addSubview(searchBar) } But when I first activate the searchBar,the placeholder text will jump upward a little,only for the first time (demo in...

Cannot disabled rotation on iPad

Image
Cannot disabled rotation on iPad The App has been released to public for months without any problem. But recently I found it can rotate screen on iPad when running iOS 9 or later. And it works without such problem on iPhone. Is it a bug of iOS 9? or I make something wrong? override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return UIInterfaceOrientationMask.Portrait } override func shouldAutorotate() -> Bool { return false } Can you choose the "Devices" is "iPad", and what is "Device Orientation" show up? – anhtu Oct 24 '15 at 2:11 @anhtu Wow, you're right! The problem solved. It's been working good on iOS 8, so I thought it as a correct setting ;-( . Can you post the answer in "Answer Your Question" so that I can accept ...

Mark successful siesta response as error

Mark successful siesta response as error I'm working with a really strange (and nasty) API that I have no control over, and unfortunately when an invalid request is made, instead of responding with a 4xx status, it responds with a 200 status instead. With this response, it also changes the response body from the usual XML response to plain text, but does not change the content type header. You can imagine how annoying this is! I've got Siesta working with the API and the fact that it is no actually RESTful in the slightest, but I'm unsure how to get the next part working - handling the unsuccessful requests. How do I go about transforming a technically valid and successful 200 response, into an error response? Right now I have the following setup: configure("/endpoint") { $0.mutateRequests { req in ... perform some mutation to request ... } $0.pipeline[.parsing].add(self.XMLTransformer) } configureTransformer("/endpoint") { ($0.content as API...

iOS: If server database order changes, how to make my UITableView reflect it?

iOS: If server database order changes, how to make my UITableView reflect it? Currently, I have a UITableView and load data from my database to my UITableView like so. UITableView UITableView - (void)getData { // self.data is my UITableView data source self.data = [Database getNumbers]; [self.tableView reloadData]; } This works well for most part, however if the number order changes because of the server. It seems I have to call getData method again. getData For example, if the the current order is 1,2,3,4,5 but the server changes number order to 1,4,2,3,5 I will have to update my database and then call getData method. getData Is there a better solution? I hate having to retrieve the numbers from database all over again and reload the tableview. This seems like the best solution however and it does work. I hope this makes sense. Ultimatly I am trying to keep the numbers in order with the server. Your title mentions FMDB. You...

Cordova Media Play sequencial Audios with delay

Cordova Media Play sequencial Audios with delay Im trying to play 3 audio files sequencially, with 1 second delay. This code works well at Android Device(actual device, after build), but on iOs(via xcode run) and browser it wait 3 seconds(3000 milisecondes) and play all at once. What could be the solution for all platforms? function playAudio(files) { var arquivos = files.split('-') for (var i = 0, length = arquivos.length; i < length; i++) { var arquivo = 'media/notas/'+arquivos[i]+'.mp3' my_media = new Media(getMediaURL(arquivo),function () {},function (err) { window.alert("playAudio():Audio Error: " + err)}); my_media.play(); console.log(getMediaURL(arquivo)) wait(1000); } function wait(ms){ var start = new Date().getTime(); var end = start; while(end < start + ms) { end = new Date().getTime(); } } while(end < start + ms) { That's a lot of CPU usage, couldn't you use await instead...

How to center table footer view in container programmatically using NSLayoutConstraint?

How to center table footer view in container programmatically using NSLayoutConstraint? I am building a screen for an app which has favorites. This screen will display the list of items that a user has favorited. This list is going to be displayed in a table view, pretty vanilla stuff. I am trying to add a little code for the empty state of the list, when no favorites have been added yet. I'd like to put a UIView in the tableFooter and then put a UILabel in the center of that view. I want the view to take up all the available space within the screen. UIView tableFooter UILabel So far this is what I have: self.tableView.tableFooterView = buildTableViewFooter() Pretty self-explanatory. func buildTableViewFooter() -> UIView { let footer = UIView(frame: self.tableView.frame) let label = UILabel() label.text = "Use the heart icon to add favorites" label.font = UIFont.italicSystemFont(ofSize: 21.0) label.textColor = UIColor.lightGray label.textAlignment = .cen...

CLLocation Timestamp is always zero

CLLocation Timestamp is always zero The CLLocation timestamp is always zero on iPhone 6+, IOS 11.4, Xcode 9.4.1. Latitude: 30.598748 Longitude: -97.820877 Altitude: 308.921658 HAccuracy: 10.000000 VAccuracy: 4.000000 Timestamp: 0.000000 <====== Is there some setting that will give me accurate timestamp? Here is the code that prints it: print("Latitude: (String(format: "%.6f", location.coordinate.latitude))") print("Longitude: (String(format: "%.6f", location.coordinate.longitude))") print("Altitude: (String(format: "%.6f", location.altitude))") print("HAccuracy: (String(format: "%.6f", location.horizontalAccuracy))") print("VAccuracy: (String(format: "%.6f", location.verticalAccuracy))") print("Timestamp: (String(format: "%.6f", location.timestamp as CVarArg))") 1 Answer 1 The ...

Do not fetch deletion changes using CkFetchRecordZoneChangesOperation

Do not fetch deletion changes using CkFetchRecordZoneChangesOperation I use it to fetch all records from cloudkit database. I pass nil token to indicate that I need ALL changes. Later I fetch latest changes with apropriate token. But first time I get thousends of changes related to deletion. It takes some time... Is there a way to indicate whether I need deletion changes or not? Or can I somehow that type of change mark as received or read and to not get it anymore? 1 Answer 1 first time I get thousends of changes related to deletion. I understand you are mentioning the scenario when you are passing nil value to the server change token in CKFetchRecordZoneChangesOptions. Is there a way to indicate whether I need deletion changes or not? Or can I somehow that type of change mark as received or read and to not get it anymore? You get the IDs of the deleted records in the block: "setRecordWithIDWa...

UISegmentedControl maintain aspect ratio on image

Image
UISegmentedControl maintain aspect ratio on image I'm having a hard time making images on a UISegmentedControl keep their aspect ratio and not scale to all sides. Here's what it looks like: The images are 100X100(except nr 6 gonna replace soon) and I want them to maintain the aspect ratio. I have tried: self.segment.contentMode = .ScaleAspectFit //and: self.segment.contentMode = UIViewContentMode.Center Are there a way I can target the UIImageView in the segment..that way I can set the contentMode..right? Or is there another approach? Thanks 3 Answers 3 segmentedControl.subviews.flatMap{$0.subviews}.forEach { subview in if let imageView = subview as? UIImageView, let image = imageView.image, image.size.width > 5 { // The imageView which isn't separator imageView.contentMode = .scaleAspectFit } } Please add an explanation. ...

Unable to use Swift object's variables in Objective-C View Controller

Unable to use Swift object's variables in Objective-C View Controller I am facing a problem accessing variables of a class written in Swift from a view controller written in Objective-C. I have already created the Bridging Header and I have successfully sent the Swift object from a view controller written in Swift to another one written in Objective-C. The problem is that I want to access the variables of the object but I get the following error: Property 'variableName' cannot be found in forward class object 'className' . Here is the class which I am trying to access its variables: import Foundation import UIKit import SwiftyJSON @objcMembers class SwiftObject: NSObject { // MARK: - Variables var id: String var name: String var contact: SwiftSubObjectA var location: SwiftSubObjectB var categories: [SwiftSubObjectC] = // MARK: - Initializers init(withJSON json: JSON) { self.id = json["id"].stringValue self.na...