I have a NSManagedObjectContext in which I have a number of subclasses of NSManagedObjects such that some are containers for others. What I'd like to do is watch a top-level object to be notified of any changes to any of its properties, associations, or the properties/associations of any of the objects it contains.
Using the context's 'hasChanges' doesn't give me enough granularity. The objects 'isUpdated' method only applies to the given object (and not anything in its associations). Is there a convenient (perhaps, KVO-based) was I can observe changes in a context that are limited to a subgraph?
Hello,
I want to pass data to a server and store the file there in a database as binary data.
NSData *myData = [NSData dataWithContentsOfFile:pathDoc];
pathDoc = [NSString stringWithFormat:@"<size>%d</size><type>%d</type><cdate>%@</cdate><file>%c</file><fname>File</fname>",fileSizeVal,filetype,creationDate,myData];
Any idea about this?
Thanks you,
Milan
Hi, I am trying to set up an application in which users will be able to stream music. When the user is streaming a MP3, I'd like to set up a link to the iTunes store to buy the MP3.
How can I do that? I feel like there should be some simple way of doing so using the song title and artist name, am I mistaking?
Thanks
Seems like a simple thing but I can't seem to find a way to do it.
I saw this but it doesn't seem to work:
NSDate *date = [NSDate dateWithNaturalLanguageString:@"07/17/07"];
It would be great to see a couple different methods.
Thanks,
Nick
Currently I am loading my supported products from a plist and after that I send a SKProductsRequest to guarantee that my SKProducts are still valid.
So I set up the request, start it and get the response in:
(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
Now, so far all functions correctly.
Problem: From calling the request until receiving the response it may last several seconds. Until that my app is already loaded and the user may be able to choose and buy a product.
But because no products have been received, the available products are not in sync with the validated products - unlikely, but possible error.
So my idea is to wait until the data is loaded and only continue when the list is validated.
(Just a few seconds waiting...). I have a singleton instance managing all products.
+ (MyClass *) sharedInstance
{
if (!sharedInstance)
sharedInstance = [MyClass new];
// Now wait until we have our data
[condition lock];
while (noEntriesYet) // is yes at begin
[condition wait];
[condition unlock];
return sharedInstance;
}
- productsRequest: didReceiveResponse:
{
[condition lock];
// I have my data
noEntriesYet = false;
[condition signal];
[condition unlock];
}
Problem: The app freezes. Everything works fine if didReceiveResponse is completed before
the sharedInstance is queried. There are different threads, the lock is working if
wait is reached during didReceiveResponse, everything fine. But if not, didReceiveResponse
is never called even if the request was sent.
The lock is released, everything looks ok. I have tried to send the product request in a separate NSThread, with NSOperationQueue...without avail.
Why ? What is happening ?
How to solve the problem ?
Does someone knows how we can combine our current recording into another background playing music? I need some sample code for this. I want to create something like karaoke application in which we can record our voice over an instrumental music.
It is my understanding that currently if you use UIImagePicker to grab a photo, it passes back back a UIImage object which doesn't include any of the geotagging information. I was wondering if it's confirmed that in OS 4 this is fixed? Or any suggestions on where to go look to see if this is fixed?
Thanks, Mark
We are caching images downloaded from our server. We write them to our local storage like this:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0] ;
NSString* folder = [[documentsDirectory stringByAppendingPathComponent:@"flook.images"] retain];
NSString* fileName = [folder stringByAppendingFormat:@"/%@", aBaseFilename];
BOOL writeSuccess = [anImageData writeToFile:fileName atomically:NO];
The downloaded images are always the expected size, around 45-85KB.
Later, we read images from our cache like this:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0] ;
NSString* folder = [[documentsDirectory stringByAppendingPathComponent:@"flook.images"] retain];
NSString* fileName = [folder stringByAppendingFormat:@"/%@", aBaseFilename];
image = [UIImage imageWithContentsOfFile:fileName];
Occasionally, the images returned from this cache read are much smaller because they are much more compressed - around 5-10KB. Has the OS done this to us?
Hi
I have to do some different views containing 72 LED lights. I built an LED Class so I can loop through the LED's and set them to different colors (Green, Red, Orange, Blue None etc.).
The LED then loads the appropriate .png.
This works fine, I loop over the LED's and set them.
Now I know that at some time they will need to not just turn on/off change color, but will have to turn on with a small delay. Like an equalizer.
I have a 5-10 views containing the 72 LED's and I would like to achieve the above with the minimum amount of memory/CPU strain.
for(LED *l in self.ledArray) {
[l display:Green];
}
I simply loop as shown above and inside the LED is a switch case that does the correct logic.
If this were actual LED's and a microController I would use sleep(100) or similar in the loop, but I would really like to avoid stuff like that for obvious reasons.
I was thinking that doing a performOnThread withDelay would really be consuming, so would UIView animation changing the alpha and NSOperation would also be a lot of lifting for a small feature.
Is there a both efficient and clever way to go around this?
Thanks for any inspiration given:)
Hi guys,
Little background, the table view is filled by a fetchedResultsController which fills the table view with Strings. Now I'm trying to add a button next to each String in each tableview cell. So far, I've been trying to create a button in my configureCell:atIndexPath method and then add that button as a subview to the table cell's content view, but for some reason the buttons do not show up. Below is the relevant code. If anyone wants more code posted, just ask and I'll put up whatever you want. Any help is greatly appreciated.
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
// get object that has the string that will be put in the table cell
Task *task = [fetchedResultsController objectAtIndexPath:indexPath];
//make button
UIButton *button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setTitle:@"Check" forState:UIControlStateNormal];
[button setTitle:@"Checked" forState:UIControlStateHighlighted];
//set the table cell text equal to the object's property
cell.textLabel.text = [task taskName];
//addbutton as a subview
[cell.contentView addSubview:button];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
I need to work with private HTTPS API and client has incorrect certificate on the host.
Certificate is for www.clienthost.com and I'm working with api.clienthost.com.
So I need to connect via HTTPS to api.clienthost.com ignoring incorrect certificate but still make sure it is the one for www.clienthost.com and not something else.
I found this answer: http://stackoverflow.com/questions/933331/how-to-use-nsurlconnection-to-connect-with-ssl-for-an-untrusted-cert and it seems to solve half of my problem but I'm trying to figure out how to still check certificate for host is one I expect to see and not different.
I feel like this should be obvious to me, but for some reason I can't figure this out. I have a navigation interface with nav bar, tool bar, and primary view. Sometimes the user takes an action that causes a progress indicator to appear in the middle of the view.
While the progress indicator (which is a custom UIView) in spinning in the middle, I want no touch input to be allowed to go to any of the underlying interface (main view, nav bar, toolbar, etc). But this doesn't seem trivial.
I've tried (and failed) to create a simple view whose only job is to swallow touch input and use it as a window subview-- no dice, it never gets the touch events (and yes, it does have userInteractionEnabled). I've tried to bolt it on as a transparent modal view controller, but those don't seem to ever be transparent.
Thoughts? What am I missing?
Thanks!
Have: xCode project with Google Analytics lib, could be normally compiled. Want just to put it to already working SVN to build project from the work macosx without any additional steps.
I've tried different ways to add *.a file to the svn, but all just have not worked. When adding a directory there is all files except *.a in the svn.
I bet there is not such problem with 3d party SVN clients, but want to give the xCode one more chance, so asking there.
Guys, is it possible to add *.a files to SVN using xCode?
I am modifying the "MoveMe" example from the apple web site. When I get the "touchesMoved" message I move the centre of the target view to the centre of the touch.
Is there a way that when the touch starts ("touchesBegan" message) I can remember the offset from the target view and keep that offset.
Let me know if this is hard to understand and I will try to explain it a bit better.
I want to pass a flag into my location manager function
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
so it will look like
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation andTweet:(Bool *)tweet
but it started with the command
[locmanager stopUpdatingLocation];
So how can I pass the bool into the function?
I'm loading profile pictures from Facebook, cache them on disk and load them into cells of a UITableView.
Now I'm wondering, how I can find out when someone has changed his/her profile picture on Facebook that I have to load the new image from the web instead of using the one cached disk.
The url of the image is always the same. Is there a lightweight way of doing this without downloading the image and comparing it to the local file?
Hi,
I am using the accelerometer to move a few UIImageViews around the screen, at the moment the accelerometer only works when a NSTimer is at 0, this is fine. I would also like to make the accelerometer stop again when a different function happens.
here is my code at the moment:
-(BOOL) accelerometerWorks {
return time == 0;
}
-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
if(![self accelerometerWorks]) return;
valueX = acceleration.x*25.5;
int newX = (int)(ball.center.x +valueX);
if (newX 320-BALL_RADIUS)
newX = 320-BALL_RADIUS;
if (newX < 0+BALL_RADIUS)
newX = 0+BALL_RADIUS;
int XA = (int)(balloonbit1.center.x +valueX);
if (XA 320-BALL_RADIUS)
XA = 320-BALL_RADIUS;
if (XA < 0+BALL_RADIUS)
XA = 0+BALL_RADIUS;
int XB = (int)(balloonbit2.center.x +valueX);
if (XB 320-BALL_RADIUS)
XB = 320-BALL_RADIUS;
if (XB < 0+BALL_RADIUS)
XB = 0+BALL_RADIUS;
int XI = (int)(balloonbit3.center.x +valueX);
if (XI 320-BALL_RADIUS)
XI = 320-BALL_RADIUS;
if (XI < 0+BALL_RADIUS)
XI = 0+BALL_RADIUS;
int XJ = (int)(balloonbit4.center.x +valueX);
if (XJ 320-BALL_RADIUS)
XJ = 320-BALL_RADIUS;
if (XJ < 0+BALL_RADIUS)
XJ = 0+BALL_RADIUS;
int XE = (int)(balloonbit5.center.x +valueX);
if (XE 320-BALL_RADIUS)
XE = 320-BALL_RADIUS;
if (XE < 0+BALL_RADIUS)
XE = 0+BALL_RADIUS;
int XF = (int)(balloonbit6.center.x +valueX);
if (XF 320-BALL_RADIUS)
XF = 320-BALL_RADIUS;
if (XF < 0+BALL_RADIUS)
XF = 0+BALL_RADIUS;
int XH = (int)(balloonbit8.center.x +valueX);
if (XH 320-BALL_RADIUS)
XH = 320-BALL_RADIUS;
if (XH < 0+BALL_RADIUS)
XH = 0+BALL_RADIUS;
ball.center = CGPointMake (newX, 429);
balloonbit1.center = CGPointMake (XA, 429);
balloonbit2.center = CGPointMake (XB, 426);
balloonbit3.center = CGPointMake (XI, 410);
balloonbit4.center = CGPointMake (XJ, 415);
balloonbit5.center = CGPointMake (XE, 409);
balloonbit6.center = CGPointMake (XF, 427);
balloonbit8.center = CGPointMake (XH, 417);
}
This all works fine, i would now like to stop the accelerometer from working, using the same
accelerometerWorks method or a new method, accelerometerWontWork.
This is the code that when it is called i would like the accelerometer to stop. (it is very long so i wont put all of it there, but its all the same throughout):
-(void) checkCollision{
if (CGRectIntersectsRect(pinend.frame, balloonbit1.frame)){
if (balloonbit1.frame.origin.y pinend.frame.origin.y){
[maintimer invalidate];
levelfailed.center = CGPointMake (160, 235);
}
}
if (CGRectIntersectsRect(pinend.frame, balloonbit2.frame)){
if (balloonbit2.frame.origin.y pinend.frame.origin.y){
[maintimer invalidate];
levelfailed.center = CGPointMake (160, 235);
}
}
if (CGRectIntersectsRect(pinend.frame, balloonbit3.frame)){
if (balloonbit3.frame.origin.y pinend.frame.origin.y){
[maintimer invalidate];
levelfailed.center = CGPointMake (160, 235);
}
}
}
I understand that i may have to turn this into a BOOL. Thats fine.
If i haven't explained it well please say and i will re write it.
Thanks!
Harry.
I used core data to do this:
NSManagedObjectContext *m = [self managedObjectContext];
Foo *f = (Foo *)[NSEntityDescription insertNewObjectForEntityForName:@"Foo"
inManagedObjectContext:m];
f.created_at = [NSDate date];
[m insertObject:f];
NSError *error;
[m save:&error];
Where the created_at field is defined as type "Date" in the xcdatamodel.
When I export the sql from the sqlite database it created, created_at is defined as type "timestamp" and the values look like:
290902422.72624
Nine digits before the . and then some fraction.
What is this format? It's not epoch time and it's not julianday format.
Epoch would be:
1269280338.81213
julianday would be:
2455278.236746875 (notice only 7 digits before the . not 9 like I have)
How can I convert a number like 290902422.72624 to epoch time? Thanks!
Hi i am developing an app for my QA department. I need to programically get how many phone numbers are there in the entire address book. No user input. Just click a button and then get how many phonenumbers are there in the ENTIRE addressbook.
Please email me at [email protected]
Hi Everybody,
I am trying to upload a image which i am clicking with the help of the camera. I am trying the following code to upload the image to the remote server.
-(void)searchAction:(UIImage*)theImage
{
UIDevice *dev = [UIDevice currentDevice];
NSString *uniqueId = dev.uniqueIdentifier;
NSData * imageData = UIImagePNGRepresentation(theImage);
NSString *postLength = [NSString stringWithFormat:@"%d",[imageData length]];
NSString *urlString = [@"http://www.amolconsultants.com/im.jsp?" stringByAppendingString:@"imagedata=iPhoneV0&mcid="];
urlString = [urlString stringByAppendingString:uniqueId];
urlString = [urlString stringByAppendingString:@"&lang=en_US.UTF-8"];
NSLog(@"The URL of the image is :- %@", urlString);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:imageData];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn == nil)
{
NSLog(@"Failed to create the connection");
}
}
But nothing is getting posted. Nothing comes in the console window also. I am calling this method in the action sheet. When the user clicks on the 1st button of the action sheet this method is called to post the image.
Can anyone help me with this...
Any code will be very helpful...
Thanx in advance...
I want to pass a flag into my location manager function
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
so it will look like
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation andTweet:(Bool *)tweet
but it started with the command
[locmanager startUpdatingLocation];
So how can I pass the bool into the function?
I have a Navigation project which has only a TableView. By default, i could see the navigation bar there when running the application. I want to change the navigation bar style to same like if we see in I.B there is one called "Top Bar" which has "Black Navigation Bar" style (Which shows Black navigation top bar but some kind of Gray shade will be there). I want the same in my navigation bar now, not any other color or style.
How do i fix it?
Note:
1. I used "self.navigationController.navigationBar.barStyle = UIBarStyleBlack;" , but it shows the navigation bar in utter black color. I don't want that, i want some kind of Gray shade in black, similar to "Top Bar" which has "Black Navigation Bar".
I tried some tint color addition to the above, like "self.navigationController.navigationBar.tintColor = [UIColor grayColor];" but i observe the same utter black shows in navigation bar.
I tried "navigationBar.barStyle = UIBarStyleBlackTranslucent;" but it doesn't fit and show with status bar properly. Instead it overlaps(hidden) half black with status bar and half black shows outside.
Could someone teach me?
Thank you.