Browsing articles in "iOS"

Navigation Controller inside a Tab Bar Controller

Jun 11, 2013   //   by admin   //   iOS  //  Comments Off

When you are using a Tab View controller based project it doesn’t come with a navigation stack by default. So if you would like have a navigation view on each tab, with a tab bar and back button, when navigating in the stack, here is the code to do so. All you need to do is modify the function: didFinishLaunchingWithOptions.

Standard Code

This is the standard code that you get when you create a tab view project:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

UIViewController *viewController1, *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPhone” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPhone” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPhone” bundle:nil] autorelease];
} else {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPad” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPad” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPad” bundle:nil] autorelease];
}
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}

Modified Function to add a Navigation Stack

All you simply need to do is embed the main view controllers for each tab inside a navigation view controller.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

UINavigationController *navController1, *navController2, *navController3;

UIViewController *viewController1, *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPhone” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPhone” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPhone” bundle:nil] autorelease];
} else {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPad” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPad” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPad” bundle:nil] autorelease];
}

navController1 = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease];
    navController2 = [[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease];
    navController3 = [[[UINavigationController alloc] initWithRootViewController:viewController3] autorelease];
    
    // navigation bar color
    navController1.navigationBar.tintColor = [UIColor blackColor];
    navController2.navigationBar.tintColor = [UIColor blackColor];
    navController3.navigationBar.tintColor = [UIColor blackColor];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[navController1, navController2, navController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}

Any problems, please feel free to send me an email.

UIWebView, allow an unverified ssl certificate (Testing only)

Feb 21, 2013   //   by admin   //   Blog, iOS  //  Comments Off

Override the following methods, this will allow unverified certificates. However, these are private methods and therefore will be rejected be Apple.

@interface NSURLRequest (NSURLRequestWithIgnoreSSL) 
+(BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
@end

@implementation NSURLRequest (NSURLRequestWithIgnoreSSL) 
+(BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host
{
    return YES;
}
@end

Getting Xcode to recognise a new provisioning profile

Jan 30, 2013   //   by admin   //   Blog, iOS  //  Comments Off

When I upgraded my provisioning certificate to distribute my iOS project in XCode I received the following error:

Code Sign error: Provisioning profile 'App-name' has expired

Even though I have updated my developer certificate, renewed my distribution certificate and fully downloaded and re-added it to the organizer. Very puzzling! This turns out to be a “feature” of Apple’s development tools.

So here is how I fixed the issue:

1. Close down your problem XCode project.
2. Open up Terminal and navigate to the directory containing your project, lets call it MyApp.
3. MyApp.xcodeproj is actually a directory, so navigate inside it, cd MyApp.xcodeproj
4. Type: sudo vi project.pbxproj, and enter your admin password when prompted. You will be presented with project.pbxproj opened in the vi editor.
5. Search for ‘/* Begin XCBuildConfiguration section */’
6. Now delete every line you find starting with the key work: PROVISIONING_PROFILE, in vi ‘dd’ is the command to delete the current line.
7. Save the file and exit (Command :wq)
8. Re-open MyApp’s XCode project and rebuild.

You should now have a fully working XCode project with an updated provisioning profile.

If you have any questions, please contact me (John)

Mac OS X Device Drivers

Nov 28, 2012   //   by admin   //   Blog, iOS, Mac OS  //  No Comments

If you want develop device driver for the Mac OS, start with these two links:

I/O Kit Device Drivers Design Guidelines: here

Creating a Device Driver in XCode: here

MPMoviePlayerPlaybackDidFinishNotification not called

Aug 15, 2012   //   by admin   //   Blog, iOS  //  No Comments


Read this it will explain all:

Notifies observers that the movie finished playing. The affected movie player is stored in the object parameter of the notification. The userInfo dictionary of this notification contains the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey key, which indicates the reason that playback finished. This notification is also sent when playback fails because of an error.

This notification is not sent in cases where the movie player is displaying in fullscreen mode and the user taps the Done button. In that instance, the Done button causes movie playback to pause while the player transitions out of fullscreen mode. If you want to detect this scenario in your code, you should monitor other notifications such as MPMoviePlayerDidExitFullscreenNotification.

The problem is probably because you are running in fullscreen mode.

iTunes Search API

Jun 25, 2012   //   by admin   //   Blog, iOS  //  No Comments

You can search iTunes by using an API and find elements like the Preview URL for songs:

http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

Example search term to get a JSON version data for tracks

http://itunes.apple.com/search?term=The+Minx+No+Friends

Renaming an iOS XCode 4.x project

Jun 3, 2012   //   by admin   //   Blog, iOS  //  No Comments

This might be very simply, but it is not obvious.

To rename an XCode project, all you need to do is select the project root in project navigator twice slowly or select it and hit enter. The project text will be highlighted, then change it to your new name and press return. A box will appear to suggest to automatically change all project-name-related entries, it will also allow you to de-select some of them.

That’s it, not obvious but very simple!

OpenCL coming with iOS 6.0

May 18, 2012   //   by admin   //   iOS, Programming  //  No Comments

OpenCL coming with iOS 6. It would be good!

Convert Milliseconds to Hours, Minutes and Seconds

May 4, 2012   //   by admin   //   C++, iOS  //  No Comments

Hours = Milliseconds / (1000*60*60)
Minutes = (Milliseconds % (1000*60*60)) / (1000*60)
Seconds = ((Milliseconds % (1000*60*60)) % (1000*60)) / 1000

We are following @PiedPiperPromo

May 4, 2012   //   by admin   //   iOS  //  No Comments

We are following @PiedPiperPromo looking forward to your events. Thanks for the plug.

Convert Integer to NSString

Apr 30, 2012   //   by admin   //   iOS  //  No Comments
int aInteger = 6; 

NSString* ourString = [NSString stringWithFormat:@"%i", aInteger]; 
Pages:1234»