Can not access EKEventStore in OSx - osx-lion

I try to use EKEventStore with checking for document in web and reference. But still got below problem that seem like I can not access store in OSx. Mine is 10.7.5, please help suggest what I did wrong on this.
#import "AppDelegate.h"
#implementation AppDelegate
#synthesize store = _store;
#synthesize defaultCalendar = _defaultCalendar;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
self.store = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityTypeEvent];
self.defaultCalendar = [self.store defaultCalendarForNewEvents];
}
- (IBAction)startPress:(id)sender {
NSLog(#"Default calendar:%# is nil:%#", [self.defaultCalendar title],(self.defaultCalendar));
NSArray *calendars = [self.store calendarsForEntityType:EKEntityTypeEvent];
NSLog(#"Total calendars %lu", calendars.count);
}
This is result that came out in Log
2013-02-02 08:24:42.429 iCalendarProfiler-Test01152013[2296:403] Default calendar:(null) is nil:(null)
2013-02-02 08:24:42.429 iCalendarProfiler-Test01152013[2296:403] Total calendars 0

EKEventStore for OS X is available since 10.8, is not available for OS X 10.7.5

Related

Bonjour NSNetServiceBrowser in iOS6 Not working

I'm working on advertising a desktop client to phones on the local network. My phone is at 6.0.2 with the Xcode 4.5.2.
I know the desktop app is registering successfully because the Discovery app (by Tildesoft) on my phone shows my service on the network (which also rules out wifi problems).
I've downloaded the Apple app example, Bonjour Web. The delegate for finding "_myservice._tcp" didn't ever fire, but the start browsing method does fire.
I tried using HHServices (which wraps DNSService), and while the start browsing method fired, the service found method doesn't fire.
In my own app, I tried using NSNetServiceBrowser. I set the delegate, and my "netServiceBrowserWillSearch" delegate method gets fired, but nothing else happens.
Code is attached if you want to verify.
Header:
#import <UIKit/UIKit.h>
#interface ClientFinder_ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate,NSNetServiceBrowserDelegate>
#property (weak, nonatomic) IBOutlet UITableView *availableClientsTableView;
-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindDomain:(NSString *)domainString moreComing:(BOOL)moreComing;
-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing;
-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict;
-(void)netServiceBrowserDidStopSearch:(NSNetServiceBrowser *)aNetServiceBrowser;
-(void)netServiceBrowserWillSearch:(NSNetServiceBrowser *)aNetServiceBrowser;
#end
Relevant Implementation:
- (void)viewDidLoad
{
[super viewDidLoad];
dictionaryFoundClients = [[NSMutableDictionary alloc] initWithCapacity:1];
[self addLogoToNabar];
[self listen];
}
-(void)listen{
NSNetServiceBrowser *serviceBrowser = [NSNetServiceBrowser new];
[serviceBrowser setDelegate:self];
[self.netServiceBrowser searchForServicesOfType:TYPE inDomain:domain];
}
-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindDomain:(NSString *)domainString moreComing:(BOOL)moreComing{
NSLog(#"aNetServiceBrowser didFindDomain");
}
-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing{
NSLog(#"aNetServiceBrowser didFindService");
[dictionaryFoundClients setObject:aNetService forKey:aNetService.hostName];
NSLog(#"Found service: %# # %#", aNetService.name, aNetService.hostName);
}
-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict{
NSLog(#"aNetServiceBrowser didNotSearch. Errors enumerated");
for(int a=0; a< errorDict.count; a++){
NSString *key = [[errorDict allKeys] objectAtIndex:a];
NSString *val = [errorDict objectForKey:key];
NSLog(#"%#: %#", key, val);
}
}
-(void)netServiceBrowserDidStopSearch:(NSNetServiceBrowser *)aNetServiceBrowser{
NSLog(#"netServiceBrowserDidStopSearch");
}
-(void)netServiceBrowserWillSearch:(NSNetServiceBrowser *)aNetServiceBrowser{
NSLog(#"netServiceBrowserWillSearch");
}
If this is all local, you need to use searchForServicesOfType: method instead of searchForRegistrationDomains method.
-(void)listen{
NSNetServiceBrowser *serviceBrowser = [NSNetServiceBrowser new];
[serviceBrowser setDelegate:self];
[serviceBrowser searchForServicesOfType:#"_your_service_type._tcp" inDomain:#""];;
}
"_your_service_type._tcp" is the service type your desktop application is using when it advertises its service.
Not sure why it started working, but here is my working code:
[self stopCurrentResolve];
[self.netServiceBrowser stop];
[self.services removeAllObjects];
NSNetServiceBrowser *aNetServiceBrowser = [[NSNetServiceBrowser alloc] init];
if(!aNetServiceBrowser) {
// The NSNetServiceBrowser couldn't be allocated and initialized.
return NO;
}
aNetServiceBrowser.delegate = self;
self.netServiceBrowser = aNetServiceBrowser;
[self.netServiceBrowser searchForServicesOfType:type inDomain:domain];

IOS RESTKIT HTTP PUT example

I want to update data in server which runs in REST API. i am using RESTKIT from ios device. But i could not find how to use PUT in restkit.
I have to send data like key:"user_id" value:"2" these format. Can anyone please help me to solve this problem.. :(
SOKeyValue.h : serialized object used as parameter for your call.
#import <Foundation/Foundation.h>
#interface SOKeyValue : NSObject
#property (nonatomic, retain) NSString* key;
#property (nonatomic, retain) NSString* value;
#end
Here's a simplified code to initialize Restkit :
/*
This part of code must be executed only one time in your application
*/
//To see logs
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
//Init with good domain
RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:#"http://mydomain.dev/ui/v1"];
//Indicate to use JSON
[RKObjectManager sharedManager].serializationMIMEType = RKMIMETypeJSON;
//Route path when you call a PUT with SOKeyValue class
[manager.router routeClass:[SOKeyValue class] toResourcePath:#"/yourpath" forMethod:RKRequestMethodPUT];
//Serialization for SOKeyValue class
RKObjectMapping* keyvalueSerializationMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class] ];
[authSerializationMapping mapAttributes:#"key", #"value", nil];
[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:keyvalueSerializationMapping forClass:[SOKeyValue class] ];
Now we can implement a service who use PUT. In the object that will implement the call dont forget the restkit delegate RKObjectLoaderDelegate:
#import <Foundation/Foundation.h>
#import <RestKit/RestKit.h>
#import "SOKeyValue.h"
#interface MyViewOrMyServiceObject: NSObject <RKObjectLoaderDelegate>
- (void)putKeyValue;
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects;
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error;
#end
In your (.m) :
- (void)putKeyValue
{
SOKeyValue *keyvalue = [[SOKeyValue alloc] init];
keyvalue.key = #"k";
keyvalue.value = #"2";
[[RKObjectManager sharedManager] putObject:keyvalue delegate:self];
[keyvalue release];
}
You can see status code in your trace, and use callback functions :
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects;
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error;
So i dont have MAC at home, it's diffcult for help you about the code structure. If you have questions do not hesitate.

Simple Save/Load the entire array

I'm new. Been trying to save/load a couple of arrays but to no avail.
I have "Global.h" and "Global.m" providing arrays for other classes.
in Global.h
extern NSMutableArray *arrayTable;
extern NSMutableArray *arrayPurpose;
#interface Global : NSObject <NSCoding> {
}
in Global.m
NSMutable *arrayTable;
MSMutable *arrayPurpose;
I have other views/controllers/classes/whatever that work with these arrays and they are functioning. What do I put inside this "Global" and the "AppDelegate.h" and "AppDelegate.m" so that these arrays are saved when this app goes into background and loads when the app starts? I need to use this "NSDocumentDirectory" because this data is important.
Please keep your explanations REALLLLLLY EASY. I have less than a week's experience. Thanks!!
Edit: Did what Joris suggested.
Added this to the AppDelegate
-(NSString *)archivePath {
NSString *docDir =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)objectAtIndex: 0];
return [docDir stringByAppendingPathComponent:#"TableData.dat"];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[NSKeyedArchiver archiveRootObject:arrayTable toFile:self.archivePath];
[NSKeyedArchiver archiveRootObject:arrayPurpose toFile:self.archivePath];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:rootController.view];
[self.window makeKeyAndVisible];
arrayTable = [NSKeyedUnarchiver unarchiveObjectWithFile:[self archivePath]];
arrayPurpose = [NSKeyedUnarchiver unarchiveObjectWithFile:[self archivePath]];
if (arrayTable == nil) {
arrayPurpose = [[NSMutableArray alloc]init];
arrayTable = [[NSMutableArray alloc]init];
}
return YES;
}
Not very detailed but:
in the suspend method of your appdelegate you can use:
[NSKeyedArchiver archiveRootObject:arrayTable toFile:...];
and in the resume method:
arrayTable = [[NSKeyedUnarchiver unarchiveObjectWithFile:...] retain];

NSMutableArray not accessible throughout my class?

I'm really frustrated after spending like three hours googling around to solve this problem!! It's probably an easy solution to it aswell.
I'm creating a really simple TableView app for the iPhone. It's supposed to fetch an XML-document and parse it (already fixed) and then put the data into objects called HPobject!
One HPobject represents one day of data from the XML-file. Anyhow!
Then I want the object to be stored in a NSMutableArray so I can grab it later when I'm creating the table rows. But I can't access it! My NSMutableArray is ALWAYS null! No matter what I do!
Here's my code:
//THE .h FILE
#import "TBXML.h"
#import "HPobject.h"
#interface RootViewController : UITableViewController {
NSMutableArray *listOfItems;
}
- (void)traverseElement:(TBXMLElement *)element;
//THE .m FILE
#import "RootViewController.h"
#import "HPobject.h"
#implementation RootViewController
- (void)viewDidLoad
{
NSMutableArray *listOfItems = [[NSMutableArray alloc] init];
TBXML * tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:#"http://www.hpprov.se/istasts.php?q=xxxxxxx"]] retain];
if (tbxml.rootXMLElement)
[self traverseElement:tbxml.rootXMLElement]; //Works fine!
[tbxml release];
[super viewDidLoad];
}
- (void) traverseElement:(TBXMLElement *)element {
do {
//Lots of parsing code which all works fine and gets me the variables up next!
HPobject *currentObject = [[HPobject alloc] init];
currentObject.antalRegistrerade = numRegistrerade;
currentObject.inkomstBrutto = numBrutto;
currentObject.inkomstNetto = numNetto;
[listOfItems addObject:currentObject];
NSLog(#"Array: %#", listOfItems); //RETURNS null!
NSLog(#"Reg: %#, Net: %#, Brutt: %#", currentObject.antalRegistrerade, currentObject.inkomstNetto, currentObject.inkomstBrutto); //Returns the correct values!
NSLog(#"%d stycken!", listOfItems.count); //Returns 0!! :(
[currentObject release];
} while ((element = element->nextSibling));
}
You are defining listOfItems locally in viewDidLoad and then you try to access that in another method.
Make sure you are using an instance variable defined in your interface definition (header).
replace this line in viewDidLoad:
NSMutableArray *listOfItems = [[NSMutableArray alloc] init];
with
listOfItems = [[NSMutableArray alloc] init];
I suppose that listOfItems is an ivar. So to fix your problem change this:
NSMutableArray *listOfItems = [[NSMutableArray alloc] init];
to this
listOfItems = [[NSMutableArray alloc] init];
Take a look at the scope of your array. You have created that as a variable of another method. It will not visible in others. Make an instance var.

CMMotionManager and the Gyroscope on iPhone 4

I am trying to simply NSLog the output of the new iPhone 4 Gyroscope. But after reading the documentation and following their sample code I am getting this error.
ERROR,Time,300635803.946,Function,"CLLoggingSetFile",could not open locations log /var/mobile/Library/Caches/CoreMotion/CoreMotion.log
Even if I just setup my motionManager object with [[CMMotionManager alloc] init]; on its own and no other code, I still get the error.
Here is my .h file.
#import <UIKit/UIKit.h>
#import <CoreMotion/CoreMotion.h>
#interface GyroTest0ViewController : UIViewController {
CMMotionManager *motionManager;
NSOperationQueue *opQ;
}
#end
And here my .m file.
- (void)viewDidLoad {
[super viewDidLoad];
// the error occurs even just with this line on its own
motionManager = [[CMMotionManager alloc] init];
if (motionManager.gyroAvailable) {
motionManager.gyroUpdateInterval = 1.0/60.0;
[motionManager startGyroUpdates];
opQ = [[NSOperationQueue currentQueue] retain];
CMGyroHandler gyroHandler = ^ (CMGyroData *gyroData, NSError *error) {
CMRotationRate rotate = gyroData.rotationRate;
NSLog(#"rotation rate = [%f, %f, %f]", rotate.x, rotate.y, rotate.z);
};
} else {
NSLog(#"No gyroscope on device.");
[motionManager release];
}
}
Any help and/or source code to simply log the iPhone 4 gyroscope data would be much appreciated. Many thanks!
Try this,
motionManager.gyroUpdateInterval = 1.0/60.0;
[motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler: ^(CMGyroData *gyroData, NSError *error)
{
CMRotationRate rotate = gyroData.rotationRate;
NSLog(#"rotation rate = [%f, %f, %f]", rotate.x, rotate.y, rotate.z);
}];
For the WWDC sample code:
Log in to ADC
Click on WWDC 2010 session videos
View in iTunes
There you find the link to sample code (230 MB)
Any results regarding this issue? I get the same error even when I use WWDC teapot demo code.
I filed a bug report (8382659).
By the way I get the same error when I use the push method described by Joshua Weinberg.
Update: Apple confirmed the bug but referred to a duplicate issue 8173937 that I can't find. Well let's hope that it will be fixed in the next release.