cocoa,core-motion , CMPedometer is not running


CMPedometer is not running

Question:

Tag: cocoa,core-motion

My CMPedometer is not running.

The code before it and after it gets run, but it itself does not work. I get no warning or exception. I'm testing it on a real 5s.

I've tried both querydata and startpedometerupdates.

I am importing core motion and the library is linked.

Any help?

if ([CMPedometer isStepCountingAvailable] == YES)
    {
    CMPedometer *cmped;
    [cmped queryPedometerDataFromDate:start toDate:[NSDate date] withHandler:^(CMPedometerData *pedometerData, NSError *error){
        stepslabel.text = [pedometerData.numberOfSteps stringValue];
    }];

    }

Answer:

It seems really odd but I got it working by not declaring in the .h or before using it. What worked was declaring as @property CMPedometer *cmped; right after interface


Related:


Keep both NSSplitViewController's child controllers in first responder chain


osx,cocoa
I've a document based app with an NSSplitViewController as the main window's content view controller. The left pane contains a custom view with controller, which implements some menu commands. The right pane contains a standard NSTableView with controller. When the app starts the menu commands work as expected, but as...

What is the best way to make sure I am not using any unavailable API's on OSX?


objective-c,xcode,osx,cocoa
I am writing an OSX app in Xcode 6 but want my application to have support for OSX 10.7 and up. Unfortunately Xcode 6 only includes SDK for 10.10 and 10.9. What is the best way to make sure I am not using any unavailable API's that would crash on...

Please help protocol code that does not make sense


ios,objective-c,cocoa
i'm stumped with part of this statement: @property(nonatomic, readonly) NSArray <id<NSFetchedResultsSectionInfo>>*sections this property belongs to NSFetchedResultsController Class. although NSFetchedResultsSectionInfo is a protocol, id<NSFetchedResultsSectionInfo> is an object type that must conform to the NSFetchedResultsSectionInfo protocol. id<NSFetchedResultsSectionInfo> is not a protocol so enclosing them in angle brackets <id<NSFetchedResultsSectionInfo>> makes no sense. the...

NSPredicate crash with path which contains square brackets


objective-c,cocoa,nspredicate
I have to search paths which contains square brackets in it from core data. But when I trying to create search query like below, xcode crashes. path == /my/local/[path] I've tried to escape square brackets, from one brackets to 16 brackets, but nothing works. That path is from another application,...

Binding an NSTableView to an array of strings in Swift


osx,swift,cocoa,nstableview,cocoa-bindings
I'm showing the contents of an array of strings with an NSTableView via binding through an Array Controller. I have "NSString" in Class Name in the attributes inspector for the Array Controller and in the Model Key Path of the Array Controller's binding inspector I have the path to my...

How to get custom table cell views into NSTableView?


osx,swift,cocoa,nstableview,nstableviewcell
I have a NSTableView that uses mostly standard NSTextTableCellViews but I want some other cells that contain another UI component in my table in one or two rows. The question is: Where do I define those custom cells so that Cocoa finds them? I just dropped a custom NSTableCellView into...

iOS9 error on activityManager.startActivityUpdatesToQueue


ios,swift,core-motion,ios9
I opened my app in the new Xcode7 beta which worked perfectly fine in older version. Now I'm receiving errors, and i don't know how to solve it. Here is the code. Error is commented out. import UIKit import CoreMotion class ViewController: UIViewController { let activityManager = CMMotionActivityManager() let pedoMeter...

self.revealViewController becomes nil and SWRevealViewController Menu not showing after segue back to SWRevelViewController from a certain VC


ios,objective-c,cocoa
I'm using the SWRevelViewController framework and met this problem while coding. Basically here's the list of my VCs and their classes: http://mnch.in/ubyB/3g4uqSwl (picture of my story board) The problem is when user logged in in UIVC_2, it goes back to SWRevelVC using the segue marked in blue. However, when the...

Set CALayer Gradient Background


objective-c,xcode,osx,cocoa,cocoa-touch
I am trying to add a gradient to a CALayer I have created. I can set the background colour of the CALayer with the following: self.colorLayer = [CALayer layer]; [self.colorLayer setBackgroundColor:color.CGColor]; [self.colorView setWantsLayer:YES]; [self.colorView setLayer:self.colorLayer]; I've looked around with no success (surprisingly I thought this would have been answered many...

How to get NSTableView to use a custom cell view mixed with preset cell views?


osx,swift,cocoa,nstableview,nstableviewcell
I have a NSTableView configured in Interface Builder which uses several default cell views. However the first column's cell view needs to be created from a custom class. How do I implement NSTableViewDataSource method tableView.viewForTableColumn() so that it creates the default cell views for the remaining columns? Here's my method...

Is it possible to obtain an unique iCloud user ID on cocoa?


ios,iphone,cocoa,ipad,icloud
My iOS app is currently on beta in TestFlight, and as a way to retribute to the nice people who helped me test it I would like to offer them some goodies such as, for instance, the full final version of the app for free. For this, I was thinking...

How do I customize NSOutlineView to have border color?


objective-c,osx,cocoa,interface-builder,nsoutlineview
I have looked over the google but have not found many examples on this. Most only relate to the NSTableView. How do I subclass my NSOutlineView to look exactly like XCode's plist editor? I've do not know how to get the border colors shown below. I currently have it working...

Stop async operations on window close


swift,cocoa,appdelegate
In my app delegate I have put the callback to stop the program when the window is shut. func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool { return true } This doesn't work however because (I assume) there is an async bluetooth task running. What is the best way to stop everything running...

creating a wrong NSDate


ios,objective-c,iphone,cocoa,nsdate
This is the code NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setDay:13]; [comps setMonth:6]; [comps setYear:2015]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *date = [gregorian dateFromComponents:comps]; NSLog(@"date = %@", date); the result is 2015-06-12 23:00:00 +0000 12? the day is 13!!! Why is that happening? Bug? ...

Cursor doesn't update in NSTextField as it autoresizes when resizing the enclosing NSWindow


objective-c,cocoa,nstextfield,autoresize,nscursor
I have an NSTextField that autoresizes. Its text is centered. When I start typing in the field and then resize the enclosing NSWindow, the cursor stays where it's at rather than repositioning to the appropriate place : I've also made an XCode project demonstrating this problem : https://www.dropbox.com/sh/cohhmslyl9ti43b/AAC6ULteopsQCMDsEArJU15Ta?dl=0 Does anyone...

Restrict input on NSTextField


osx,swift,cocoa,nstextfield
I want to restrict character input on NSTextField, i.e. so that disallowed characters aren't even appearing. Most of what I found about this topic were solutions that only validate after text input finished or using NSFormatter which still allows the character to appear. So far I came up with this...

Why @selector can call a method which is declared in an implementation file?


objective-c,cocoa,nsnotificationcenter
I have declared (between @interface and @end) and implemented a method in the .m file of Class A. For instance: - (void)zoneChange:(NSNotification *)note { NSLog(@"The system time zone has changed!"); } And in Class B, I want to send zoneChange message to a observer when the system zone is changed....

Default Cocoa Application ViewController.m issue?


objective-c,osx,cocoa
Newbie question follows... I am learning Objective C based OS X Cocoa app development. Most of the books and videos I have are for iOS, so I am converting some simple iOS code examples to OS X. When I create a new OS X "Cocoa Application" project, with the "use...

Cocoa ViewController.m vs. Cocoa Touch ViewController.m


objective-c,osx,cocoa
Total newbie question follows... I am learning Objective C based Cocoa (OS X) app development. Most of the books and videos I have are iOS based, so I'm seeing how the two platforms differ. I have converted a simple iOS app to OS X. I got the converted OS X...

Change views inside NSSplitViewController


swift,cocoa,nssplitview
I'm trying to migrate my Objective-C and now improving Swift knowledge to an application for Mac OS X. Steep learning curve! I'm trying to load a NSSplitViewController with different views in the "detail view" depending on buttons pressed on the "master view" if you will. Following tutorials and searching for...

NSRTFPboardType & paste into gmail browser window?


objective-c,cocoa,rtf,nspasteboard
I have a NSTextView which contains some text with attributes (syntax highlighting). I'm trying to have a copy option which keeps the syntax highlighting so that I can paste it into a gmail text window. Currently the highlighting does not appear when I copy paste it, however if I were...

Unexpected NSWindow becomes key window


objective-c,cocoa,nswindow,keywindow
I have a main NSWindow in my application with a button. When the button is pressed it does something like the following: NSWindow *newWindow = [NSWindow initWithContentRect:[screen frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; [newWindow makeKeyAndOrderFront:self]; [self.previousWindow orderOut:self]; This works fine most of the time, but if I have a second window open...

How do you work with views in MainMenu.xib?


objective-c,xcode,osx,cocoa
I'm coming over from iOS development and I can't figure out this basic thing: if I open MainMenu.xib in Interface Builder and I drag a button onto the main window's view, what class should I connect that button's action to -- the App Delegate? If I want to add a...

Selecting global or object function


swift,cocoa,swift2
I am working with on a Cocoa project in Swift and confronted the following problem: Several classes in the Cocoa Framework (such as NSWindow or NSView) implements a function called print: that opens a window in order to print something (don't really know what), so when I work within a...

Mac - How to programatically hide NSApplicationActivationPolicyAccessory or LSUIElement application?


osx,cocoa
I have a small Swift-based Cocoa app that I'm writing. It's a single window app, something like Spotlight/QuickSilver/Alfred. It's set as NSApplicationActivationPolicyAccessory (docs) (though I've tried the same thing using LSUIElement, which is equivalent). It's activated via a global hot key. Everything works well, except that when it's active I...

Using custom NSValueTransformer subclass with bindings and reverseTransformedValue method


objective-c,cocoa
I'm writing a Cocoa App using Bindings. I have a NSSlider as well as a NSTextField. Whereas the Slider's value is bound to the value returned by the transformedValue method, the TextBox should be bound to the reverseTransformedValue method. How may I achieve this? For the Slider I entered the...

Change NSTextField border and BG color while editing


osx,swift,cocoa,nstextfield
I have a NSTextField that uses no border and window background color while it is displayed but I want it to change to have the default border and white BG color when being edited. I know I can change these properties with: nameTextField.bezeled = true nameTextField.backgroundColor = NSColor.textBackgroundColor() What I...

Open New Window in Swift


osx,swift,cocoa,storyboard,nswindow
I am trying to open a new window in my Swift application but I cannot get it to open. class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(aNotification: NSNotification) { openMyWindow() } func openMyWindow() { if let storyboard = NSStoryboard(name: "Main",bundle: nil) { if let vc = storyboard.instantiateControllerWithIdentifier("MyList") as? MyListViewController { var...

Command-Line Testing Using Cocoa Touch


xcode,cocoa,kif
I have developed several test for an application, and I would like to run this application using the command-line. I have read this tutorial; however, I haven't been able to run them. When executing the following command: xcodebuild test -project MyApplication.xcodeproj -scheme MyApplication -destination 'platform=iOS Simulator,name=iPhone 6' I am getting...

How to get storage capacity of mac programatically?


objective-c,xcode,osx,cocoa,storage
I am having a mac app. As shown in the screenshot, I want to get this programmatically in my cocoa application for Mac OS X. I want to get the total capacity, available space and free space. Can anyone help me on this? Thanks......

Overuse of NSView -> Alternatives?


objective-c,osx,performance,cocoa,nsview
I having some Performance troubles with my app: It takes more than 2 seconds to load -> So straight away I went to Apple documentation https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaPerformance/Articles/CustomViews.html#//apple_ref/doc/uid/TP40001443-CJBJIFGC In the section named "Avoid the Overuse of Views" at the bottom I got very confused: I indeed adding a lot of NSViews (Guess...

What's special about an ampersand in an NSUndoManager action name?


osx,cocoa,undo
I notice that if I say something like [self.undoManager setActionName: @"X & Y"]; then the resulting menu item looks like "Undo X Y" (with a double space between X and Y). (Tested on Mac OS X 10.7.5 and 10.10.3.) I can make the ampersand show up by doubling it, but...

Does it necessary to go back to main thread to update UI?


ios,objective-c,cocoa
I was using AFNetworking to deal with the http request.And here is my code: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager POST:URL_LOGIN parameters:parames success:^(AFHTTPRequestOperation *operation, id responseObject) { [self.tableview reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Request failed"); }]; or: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager POST:URL_LOGIN parameters:parames...

Initializing a xib view as a subview of another NSView


objective-c,osx,cocoa,xib,nib
I'm trying to learn OSX development, and I've created a view in a .xib file, and I'm trying to initialize and then add this view as a subview. I've googled how to do this, and all of the solutions are for iOS and use a call such as MyViewClass* myViewObject...

How to set screensaver thumbnail in Settings panel on Mac?


osx,cocoa,screensaver
I'm making a custom *.saver application, and I would like to add my own thumbnail to show up above the name of screensaver (the ladybug pictures in the left column). How do I do that? ...

How to create few apps in one bundle?


objective-c,osx,cocoa
I have an application that runs as an agent and has icon in the top bar. It should be able to run another app with window and icon in the dock. Both should to share same core data. Is there way to do it? How to open one app from...

startAccelerometerUpdatesToQueue Type of expression is ambiguous without more context


swift,core-motion,swift2
I am trying to translate the following code to Swift 2. manager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue()) { [weak self] (data: CMAccelerometerData!, error: NSError!) in self!.outputAccData(data.acceleration) } But this gives me the following error. Type of expression is ambiguous without more context Does anyone know why this is happening?...

NSTableView - how to get automatic and manual sorting working together?


osx,swift,cocoa,sorting,nstableview
I have a NSTableView in MyViewController and have an array controller bound to it. I want to be able to sort it by clicking the table column headers and it should also auto-sort. So for auto-sort I set the Sort Descriptors binding of my array controller in IB as following:...

Too many arguments to function call, expected 0 method_invoke


objective-c,cocoa,objective-c-runtime
I'm trying to run the method id method_invoke ( id receiver, Method m, ... ); from the Objective-C runtime library but the compiler is saying I'm passing too many arguments, with it expecting 0. Why might this be? (swizzledMethodOriginalImplementation is of type Method) -(NSMenu*) blah2: (NSEvent*)anEvent :(NSRect) cellFrame :(NSView*) aView...

Why does the window background remain black in fullscreen?


osx,swift,cocoa,xcode6,storyboard
I have created a window without title by- override func windowDidLoad() { super.windowDidLoad() self.window?.styleMask = NSBorderlessWindowMask self.window?.movableByWindowBackground = true } I have set canBecomeKeyWindow by- override var canBecomeKeyWindow:Bool { get{ return true } } I have changed the background color of container view by- override func drawRect(dirtyRect: NSRect) { super.drawRect(dirtyRect)...

Unified title and toolbar in swift with storyboards without title visibilty


osx,swift,cocoa,xcode6
I want unified title toolbar like in calendar app without title. I have tried following- in viewDidLoad I added- self.view.window?.titleVisibility = .Hidden I have selected unified title and toolbar in attribute inspector. I also tried adding titleVisibility to 1 in user defined runtime attributes in identity inspector. I am not...

Apple watch standup detection


ios,watchkit,core-motion
I am now working on a app dealing with user's motion on the Apple watch. As shown on the Apple Watch, it recognize when you are sitting or standing. Is there any way to get access to it using API? Thanks

blocks and the stack


cocoa,objective-c-blocks
According to bbum: 2) Blocks are created on the stack. Careful. Consider: typedef int(^Blocky)(void); Blocky b[3]; for (int i=0; i<3; i++) b[i] = ^{ return i;}; for (int i=0; i<3; i++) printf("b %d\n", b[i]()); You might reasonably expect the above to output: 0 1 2 But, instead, you get: 2...

What is a “non-weak zeroing reference”


objective-c,cocoa,memory-management,nsnotificationcenter,osx-elcapitan
In the OS X v10.11 beta release notes, I find the following: NSNotificationCenter and NSDistributedNotificationCenter no longer send notifications to registered observers that may be deallocated. If the observer is able to be stored as a zeroing-weak reference the underlying storage stores the observer as a zeroing weak reference. Alternatively,...

Swift NSViewController responds to mouseDown event, but not keyDown event


cocoa
I am trying to create an application for OS X using Swift and Cocoa. I want the application to respond to key events without the focus being on/in a text field. I created a new Cocoa project with storyboards in Xcode, and have modified the ViewController.swift class to the following:...

How to set the default writing direction for NSTextView?


osx,swift,cocoa,interface-builder,nstextview
I'm trying to set up a text view that a user can type Hebrew text into from right-to-left. Currently it defaults to a left-to-right text direction, which the user can manually change by right-clicking and selecting "Writing Direction > Right to Left", but what I need is for the text...

Imports and includes in header files - when is it okay?


objective-c,cocoa,cocoa-touch
I've read that the rule is to not #import or #include anything in .h files. Is that really true, though? Just today I've run into two separate occasions where I had to do it, one where I import a header file that contains a typedef enum because my method stubs...

updateTrackingAreas: override only works for the first 2 times?


objective-c,xcode,osx,swift,cocoa
On El Capitan in Xcode 7 beta using Swift 2.0, I subclassed a NSView to use as a prototype view of NSCollectionView's item view, and override the updateTrackingAreas: method to do the mouse tracking. The NSCollectionView was inside a NSPopover. It seems that only the first 2 times the updateTrackingAreas:...

Cancelling dispatch_io_read


objective-c,swift,cocoa,libdispatch
I'm parsing a very large CSV file using GCD functions (please see code below). If I encounter an error I'd like to cancel dispatch_io_read. Is there a way to do that? dispatch_io_read(channel, 0, Int.max, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) { (done, data, error) in guard error == 0 else { print("Read Error: \(error)")...

How to set canBecomeKeyWindow?


xcode,osx,swift,cocoa
This may be very trivial question but I am not able to figure it out. I have removed titlebar of a window by- self.window?.styleMask = NSBorderlessWindowMask self.window?.movableByWindowBackground = true Now Any textfield is not working and are disabled because without title bar canBecomeKeyWindow is set to false. Please refer This...