Don't wanna be here? Send us removal request.
Text
NSUserDefaults for App Groups
Since iOS 8 app developers are able to implement a communication between their apps (like an app with a widget). For example you want to change the settings of the widget within your app.
Actually the most developers are using therefore the "NSUserDefaults". But there is a difference between the normal and the "App Group" NSUserDefaults. Here´s an example:
NSUserDefaults for App Groups:
NSUserDefaults *SharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.example.AppGroupName"];
Standard NSUserDefaults:
NSUserDefaults *StandardDefaults = [NSUserDefaults standardUserDefaults];
Complete App Group Example
NSUserDefaults *AppGroupsExample = [[NSUserDefaults alloc] initWithSuiteName:@"group.appname.AppGroups"]; NSInteger Variable = [AppGroupsExample integerForKey:@"Test"]; Variable = 1; [AppGroupsExample setInteger:Variable forKey:@"Test"];
Important: In order to use NSUserDefaults for App Groups you need to register an "App Group" at the Apple Developer Center at the "Certificates, Identifiers & Profiles" page. Additionally you need to add the "App Group" option to your app (Select target > Capabilities > App Groups).
More Information about NSUserDefaults
If you have questions send me a mail to hi(at)developing.io.
0 notes
Text
Parsing a text file from an url and convert it into a NSString
Sometimes it´s necessary to get data from a file which is hosted on a website (for example a .txt file). Generally you can get this query with just a few lines of code:
NSURL *url = [NSURL URLWithString:@"http://developing.io/example-file.txt"]; NSStringEncoding encoding = 0; NSError *error = nil; NSString *string = [[NSString alloc] initWithContentsOfURL:url usedEncoding:&encoding error:&error]; NSLog(@"String %@",string);
In order to use this you have to replace the url with your url of the .txt file.
That´s it!
0 notes
Text
Tutorial: Build a Barometer App
In this tutorial you´ll learn how to build a barometer app using the built in pressure sensor in iPhone 6 / iPhone 6 Plus.
You´ll need Xcode 6.x.x in order to develop this app. Please notice when run the app in the simulator that no data will be shown.
First start Xcode and create new project and choos a single view application.
After this step you need to add the CoreMotion framework to your project - it´s needed to communicate with the pressure sensor.
Next switch to the Main.storyboard file and add two labels to your view.
When you have done that head over to your ViewController.h. Now you need to include your framework to your ViewController header file.
#import <CoreMotion/CoreMotion.h>
Now connect the labels with the header file:
The ViewController.h file should now look like this:
#import <UIKit/UIKit.h> #import <CoreMotion/CoreMotion.h> @interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *Pressure; @property (weak, nonatomic) IBOutlet UILabel *RelativeAltitude; @end
Afterwards head over to the ViewController.m file and add the following code:
#import "ViewController.h" @interface ViewController () @property (nonatomic, strong) CMAltimeter *altimeter; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. if([CMAltimeter isRelativeAltitudeAvailable]){ self.altimeter = [[CMAltimeter alloc]init]; [self.altimeter startRelativeAltitudeUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAltitudeData *altitudeData, NSError *error) { _Pressure.text = [NSString stringWithFormat:@"%.02f", altitudeData.pressure.floatValue]; _RelativeAltitude.text = [NSString stringWithFormat:@"%.02f m", altitudeData.relativeAltitude.floatValue]; /** the "%.02f" are defining the decimals **/ }]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
0 notes
Text
Managing Status Bar Styles
In this short tutorial you´ll learn how to change the status bar style within your application. This is quite easy, because you really need just a few lines of code.
- (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; }
This is the function of the type UIStatusBarStyle which allows us to change the style by returning the new style.
You can just return these styles:
return UIStatusBarStyleDefault;
Default equals black.
return UIStatusBarStyleLightContent;
Light equals white.
When the status bar style has changed within the above written code use this "call" to refresh the status bar:
[self setNeedsStatusBarAppearanceUpdate];
Please send me a mail if there is something unlogically or not understandable - [email protected].
Thank you!
0 notes
Text
Importance of getting featured by a website
Two weeks ago I´ve published a new application called SkyWidgets, which is a movement tracking app. The app just has a simple startup view and a few settings to configure the units you want to display in the included widgets inside the Notification Center. Generally you can say it´s a very simple application which you can develop very easy.
Personally I´m releasing applications since 2012 in the App Store and my apps never got featured on any website. Every application I´ve released before SkyWidgets had an average download rate by ±25 downloads per day.
With SkyWidgets I broke this average. A website called "Redmondpie" has featured the app in one of their articles. Literally I was really surprised when I viewed the downloads graph at iTunes Connect - it showed ±1300 downloads in the first two days. It was really amazing and I´ve made the experience that writing press releases for websites are very important for a successful launch.
For information about how to write a press release I recommend you to take a look at Dan Counsell´s website! (http://dancounsell.com/articles)
To sum it up I really recommend you to send out press releases to websites.
This was a little bit off topic but I thought that this topic is also very useful for developers.
Stay tuned new articles are coming soon!
0 notes
Text
Load image from URL and display it inside an UIImage view
In this short entry you´ll learn how to load a external located image and display it inside an UIImage view.
For that you need to create the URL by using the NSURL type. Afterwards you typically use a string as the URL, so you need to append the string to the NSURL by typing the first line of the code below.
Now you´ve created the url -- now let´s add this to the NSData type which will be used for loading the image in the [UIImage imageWithData:imageData] code.
After the image has been loaded you can display it inside the image view.
Here is the complete code:
NSURL *url = [NSURL URLWithString:@"url_image"]; NSData *imageData = [NSData dataWithContentsOfURL:url]; UIImage *image = [UIImage imageWithData:imageData]; ImageView.image = image;
Please notice that the image will be cached by the application.
In order to delete the cache you can use this line of code:
[[NSURLCache sharedURLCache] removeAllCachedResponses];
0 notes
Text
How to get the table view background blurred
This article will guide you how to blur a background image from an UITableView. In the sample code below you start with creating an UIImageView which will bei initalized with our image. After that we create an UIVisualEffect and set up the style of it.
You can use the following styles: - UIBlurEffectStyleDark - UIBlurEffectStyleLight - UIBlurEffectStyleExtraLight
In addition we need to create a UIVisualEffectView which will be initialized with the UIVisualEffect. Now you set the frame of the UIVisualEffectView to imageView.bounds. Afterwards simply add the VisualEffectView as a subview of the image view.
Complete Code:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourIMAGE.jpg"]]; UIVisualEffect *blurEffect; blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; UIVisualEffectView *visualEffectView; visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; visualEffectView.frame = imageView.bounds; [imageView addSubview:visualEffectView]; [self.tableView setBackgroundView:imageView];
0 notes
Text
Add a Sharing Option to your App
This article will guide you about how to add a sharing option to your application.
For example the code below will share an integer value which is included in an NSString. Furthermore it´s important that you can share multiple objects through the array.
Sample Code:
NSString *string; string = [NSString stringWithFormat:@"Shared Integer", myinteger]; NSArray *objectsToShare = @[string]; UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; [self presentViewController:controller animated:YES completion:nil];
0 notes