how to start 3rd party apps in your iphone app from cocoa

to start iphone apps from your app is very simple. you only have to call an url. for example for “http://” safari is respondig:

http://www.google.com -> opens safari

with “fb://” the facebook app is responsible.

to open such an url you only have to write:

[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"http://....."]];

for information see:

http://wiki.akosma.com/IPhone_URL_Schemes (big collection of possible url schemes)

http://iphonedevtools.com/?p=302 (for facebook app)

to determine if you can open a specific app on the iphone in cocoa like facebook with “fb://” just call:

if ([[UIApplication sharedApplication] canOpenURL:url])
Posted in iOS development | Leave a comment

adding an event to the calendar from your app

with iOS 4.0 apple gave us the opportunity to access the iPhone’s calendar and adding new events to the calendar database of the iPhone your app is running on. to get this working you have to add the EventKit framework to your Xcode project und to import the framework header in your code.

#import <EventKit/EventKit.h>

the following lines of code will show you how to add a simple event to the iPhone calendar from within your own iPhone app. we will set a title, the start and end date, the location and add some notes to the event and save it to the iPhone-user’s calendar:

//create instance of EKEventStore
EKEventStore *eventStore = [[EKEventStore alloc] init];

//creating instance of EKEvent
EKEvent *event  = [EKEvent eventWithEventStore:eventStore];

//setting the appropriate properties of the new event
event.title     = @"mom's birthday";
event.startDate = [[NSDate alloc] init];
event.endDate   = [[NSDate alloc] initWithTimeInterval:600
                                         sinceDate:event.startDate];
event.location = @"mom's place";
event.notes = @"don't forget flowers!";

[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *error;
[eventStore saveEvent:event span:EKSpanThisEvent error:&error];
[eventStore release];
Posted in general | Leave a comment

simple UIView animations

the UIView class on the iPhone offers some very simple and mighty class methods that allow you to animate your UIView objects with only a few lines of code.

the animations you can create with these methods are created in “animation blocks”. to open a new animation block you use the method beginAnimations:context: and to close the block call the methods commitAnimations. within this aimation block you can specify how your UIView objects should be animated. this way, you can animate for example changes of the views size, its location or its transparency. you do this by changing the values of the corresponding propertys of your view. some of the propertys whose value changes can be animated are:

  • frame
  • bounds
  • center
  • alpha
  • etc.

additionally you can specify how the animations created in an animation block behave:
you can set the duration with the methods setAnimationDuration, you can specify the way the animation accelerates and decelerates with the method setAnimationCurve:.

and now, an example for a typical animation – let’s say you have an UIView object-variable named yourView and you want to fade it out smoothly with an animation, that means that its alpha value will be 0 at the end of the animation and it will be invisible:

[UIView beginAnimations:nil context:UIViewGetCurrentContext()];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];

// here you specify the value the view's property should have
// at the end of the animation
yourView.alpha = 0.0;

[UIView commitAnimations];

for now that is enough for you for building your own animations an get a mighty tool to animate your own user interfaces in a very simple and quick way.

Posted in iOS development | Leave a comment

working with instruments in xcode and console output

is it possible to run app with instruments (leak, activity monitor, allocation, …) and view the console output? yes it is. you have to go to the “spotlight”, this is the search-icon on the right upper of your screen and type “console” or “konsole” (if you have a german version). on this console the output is written when you start your iphone/ipad/ipod app with an instrument from xcode.

Posted in iOS development | Tagged , , , | 3 Comments

after memory warning level = 1 – app crashes

if you wonder why your app crashes after receiving a memory warning there could be one major reason: you have implemented the method didReceiveMemoryWarning: and in it you call [super didReceiveMemoryWarning]. this calls a release to the current view. to workaround this you should NOT call the [super didReceiveMemoryWarning].

Posted in iOS development | Tagged , , , , | Comments Off

w0framework – beta1

what is w0framework? (w-zero)

the w0framework is a (currently starting) framework for developing iphone and ipad apps. it should take most of the work out of the programers hand.

some benefits: easy asynchron download, image-resizing functions, automatically display loading indicator, …

the w0framework is fitted from consolidating often used functionality in already developed apps.

>> to download page

Posted in general | Comments Off

after adding layoutSubviews, UIScrollView does not scroll correct – UIView behavior is wrong

maybe you want to add a layoutSubview method to one of you customized views. and you are going to set the frame of a scrollView or something other new. now the problem is, layoutSubviews is called very often, when you scroll in die scrollview. there is a simple workaround to get the right behavior back:

- (void) layoutSubviews {
 CGRect newRectForSomeView;

 if (interfaceIsLandscape()) {
   newRectForSomeView = CGRectMake(...);
 } else {
   newRectForSomeView = CGRectMake(...);
 }

 if (!CGRectEqualToRect(newRectForSomeView, theView.frame)) {
   theView.frame = mainRect;
 }
}

attention: the function is interfaceIsLandscape() is only theoretical. you should replace this with your own code.

the idea is:

depending on landscape / portrait you calculate the newRectForSomeView variable. after this you compare the calculated frame with the frame which is already assigned to the view. if they differ the new rect is assigned to theView’s rect. so you are not going to update the frame property of the view every time layoutSubviews is called.

Posted in iOS development | Tagged , , | Comments Off

create custom uinavigationbar – quickstart

did you ever want to customize the appearance of a the navigation bar of your uinavigationcontroller instance more than only use its few style properties like tintcolor or translucent?

so dont’t worry, there are only two major steps to REALLY customize your navigation bar. we will do this by simply set a custom background image for your customized uinavigationbar:

1. go to your app-delegate implementation (.m) file und add the following lines of code on top of the file:

@interface UINavigationBar (MyCustomNavBar)
@end
@implementation UINavigationBar (MyCustomNavBar)
- (void) drawRect:(CGRect)rect {
    UIImage *barImage = [UIImage imageNamed:@"some_image.png"];
    [barImage drawInRect:rect];
}
@end

2. replace the image source i wrote bold “some_image.png” with your own image  you added to your xcode project.

voila! now you can go on and build your uinavigationcontroller instances like you did before and they will automatically use your custom uinavigationbar with your custom background image you defined just before.

Posted in iOS development | Tagged , , , , | Comments Off

add twitter support to your iphone or ipad app

to enable twitter support to your iphone or ipad app download twitteragent (http://amanpages.com/wordpress/wp-content/uploads/2010/01/TwitterAgent.zip) and use it in your app with one source code line to call:

[[TwitterAgent defaultAgent] twit:"hey guys i am reading web0"
withLink:@"http://www.web0.at" makeTiny:FALSE];

this is it!

Posted in iOS development | Tagged , , , , | Comments Off

new user interaction with iphone s proximity sensor

do you know the proximity sensor? this is some nice ir-sensor on the left from the headspeakers.

just the idea behind this – a new user interaction with proximity sensor

fingers do not prevent view to screen. screen is free. if you produce a reaction game this would be a nice user interaction. we are going to produce such a small game.

some sample code:

UIDevice *device = [UIDevice currentDevice];
[device setProximityMonitoringEnabled:TRUE];
if ([device isProximityMonitoringEnabled] == FALSE) {
   NSLog(@"Proximity Sensor not available");
   return YES;
}

this means: if the proximitymonitorenabled attribute is true after setting it to true you have sensor support. otherwise after setting to true it is not available. after this you can do:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(proximitySensorChanged:)
name:UIDeviceProximityStateDidChangeNotification
object:nil];

now you can define a method named: proximitysensorchanged and receive a notification if it user moves away from the sensor. just the method:

- (void) proximitySensorChanged: (NSNotification *) notification {
   [[UIDevice currentDevice] setProximityMonitoringEnabled:FALSE];
   UIDevice *device = [notification object];
   NSLog(@"Proximity: %i", device.proximityState);
}

it is NO possible to cancel the process of darkening the screen (currently).

Posted in iOS development | Comments Off

access uiview control from thread in objective c

[self performSelector:@selector(methodToExecute)
onThread:[NSThread mainThread] withObject:nil waitUntilDone:FALSE];

if you want to access a uiview control or some other things from a seperate thread you should know that your started thread has some, lets call it priviledges. and it does not have priviledges to execute some code from the main thread. with the code from above you allow the thread to execute code as it is the “main” thread. main thread in this case means the started program, which is also a thread but the main thread. the method “methodToExecute” can then call some modifications you want to.

Posted in iOS development | Tagged , , | Comments Off

wordpress editor with more functions

i recommend tinymce advanced from http://wordpress.org/extend/plugins/tinymce-advanced/ for more functionality on the wordpress wysiwyg editor. after installtion the editor has enough functions like bold, italic format function for you content. but if you want to do more on wordpress you need a good one.

installation:

1. download it from http://wordpress.org/extend/plugins/tinymce-advanced/

2. extract the files and upload the folder “tinemce-advanced” to “wp-content/plugins”

3. in wordpress menu in “plugins” / “plugins” activate the plugin

4. in “settings” / “tinymce advanced” you can configure the editor – be sure to change and add some toolbar items to see some effect ;)

thats it, just go to “posts” or “pages” and look the brave editor.

Posted in web development | Tagged , , , | Comments Off

threads in objective c

to start a thread in objectiv c, it is not necessary to generate a new class or so. just simply declarate a method, which should be executed as a thread. i think c# is also able to handle this. in objective c its like:

[NSThread detachNewThreadSelector:@selector(someMethodWhichIsExecutedLikeAThread:)
toTarget:self withObject:someObject];

this is an instance method (- (sometype) …) whith a parameter. if you want to execute a static method (+ (sometyp)…) then just execute it like this:

[NSThread detachNewThreadSelector:@selector(someMethodWhichIsExecutedLikeAThread:)
toTarget:[AClass class] withObject:someObject];

some further which could be, that you won’t call it with parameters. well that is simple. just call a class method like this:

[NSThread detachNewThreadSelector:@selector(someMethodWhichIsExecutedLikeAThread)
toTarget:self withObject:nil];

HINT: pay attention on @selector(…..:) – the trailing “:” at method selection. one time it is the other it is not.

Posted in iOS development | Tagged , , , , , | Comments Off

focus

our current focus relies on establishing content mining and text mining (crawling), mobile app development and security.

…and try to take over the world!

Posted in general | Comments Off