70th Day As An iOS Developer With No Experience

December 8, 2015 - 70th Day As An iOS Developer With No Experience

Today I learned how to detect the current permission which the user gave to your application / iOS App. My main project, as some of my readers know, uses camera and photo gallery of the iOS. Now, you will see, if you have the same project, in your App Settings (Settings > Your App) that there are switches for Photos and Camera.

With above being said, I will be making a quick tutorial on how to detect the current permission your App has. And if the user has denied the appropriate and needed permission to your app, then the app will show the user a cool alert controller.

CLICK HERE: PHOTOS AND CAMERA PERMISSION TUTORIAL

iOS Photos and Camera Detect Permission Tutorial

Welcome again to my new tutorial. This is the best way to detect and ask permission from your user. This tutorial will give your app a better UX (user experience) whenever the user disables the permission to your app. So let's get started.

You will simply read and copy paste the codes below, I will explain also if it is needed.

This is the code for checking the permission to Camera Access.

#pragma mark - check permission camera
- (void)checkPermissionForCamera
{
    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
        if(granted){
            NSLog(@"user has granted access to camera, do nothing...");
        } else {
            [self showAlertNoPermission:YES];
        }
    }];
}

And this is the code for checking the permission to Photo Gallery Access.
#pragma mark - check permission photo gallery
- (void)checkPermissionForPhotos
{
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    
    switch (status)
    {
        case PHAuthorizationStatusAuthorized:
            NSLog(@"user has authorized the photos, do nothing...");
            break;
        case PHAuthorizationStatusNotDetermined:
        {
            [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus authorizationStatus)
             {
                 if (authorizationStatus == PHAuthorizationStatusAuthorized)
                 {
                     NSLog(@"user has authorized the photos, do nothing...");
                 }
                 else
                 {
                     [self showAlertNoPermission:NO];
                 }
             }];
            break;
        }
        default:
            [self showAlertNoPermission:NO];
            break;

So I will explain the codes now. In our checkPermissionForCamera method, we will check here the permission for camera access, if the user has given the right permission, then do nothing. You can also deleted the NSLog to make your app better. Else (not), then the method will call another method, which is named: showAlertNoPermission. This method showAlertNoPermission will be posted below. It accepts one parameter, a boolean. If YES is pass, then it will show a certain message, if NO, then it will give a different message to the user.

Next, the checkPermissionForPhotos method. The explanation is simple and the same with the explanation above. You will see that there are two ways to check if the user has authorized the app to access the user's photo gallery. If the authorizationStatus is not Authorized, then it will call (again) the showAlertNoPermission method with a NO parameter.

Here is the showAlertNoPermission method.

- (void)showAlertNoPermission:(BOOL)forCamera
{
    UIAlertController *noPermissionAlert = [UIAlertController
                                             alertControllerWithTitle:@""
                                             message:@""
                                             preferredStyle:UIAlertControllerStyleAlert];
    
    NSMutableAttributedString *customFontAttrib;
    
    if (forCamera) {
        customFontAttrib = [[NSMutableAttributedString alloc] initWithString:@"We need your permission\n This app needs to access your camera.\nGo to Settings > THE_NAME_OF_YOURAPP > Camera > Switch ON."];
    }
    
    else {
        customFontAttrib = [[NSMutableAttributedString alloc] initWithString:@"We need your permission\n This app needs to access your photo library.\nGo to Settings > THE_NAME_OF_YOURAPP > Photos > Switch ON."];
    }
    
    [customFontAttrib addAttribute:NSFontAttributeName
                             value:[UIFont systemFontOfSize:14.0]
                             range:NSMakeRange(22, customFontAttrib.length-22)];
    [customFontAttrib addAttribute:NSFontAttributeName
                             value:[UIFont systemFontOfSize:18.0 weight:10.0]
                             range:NSMakeRange(0, 23)];
    [customFontAttrib addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor]
                             range:NSMakeRange(0,customFontAttrib.length)];
    
    [noPermissionAlert setValue:customFontAttrib forKey:@"attributedTitle"];
    
    UIAlertAction *ok = [UIAlertAction
                         actionWithTitle:@"Ok, I got it!"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             //Do some thing here
                             [noPermissionAlert dismissViewControllerAnimated:YES completion:nil];
                         }];
    
    [noPermissionAlert addAction:ok];
    
    // UIAlertController BG
    UIView * firstView = noPermissionAlert.view.subviews.firstObject;
    UIView * nextView = firstView.subviews.firstObject;
    nextView.backgroundColor = [UIColor avHighlightColor];
    
    noPermissionAlert.view.tintColor = [UIColor whiteColor];
    
    [self presentViewController:noPermissionAlert animated:YES completion:nil];
}

There you go guys. This codes are from my project and I wrote it. If this tutorial helped you, then share it and subscribe.

31st Day As An iOS Developer With No Experience

photo from dellapermata

October 16, 2015 - 31st Day As An iOS Developer With No Experience

FRIDAY - Back to my first project again. One of my favourite project. It has a paid version, wherein you can store your photos and videos privately and securely - the function I am afraid that I can't do it. Sad.

Anyway, I decided to revise my camera function. Because I really need to implement the design that the client wants. The design has a custom photo and camera function, so yeah, I decided to start the camera function from the scratch. It is so pretty easy to do it. Just download an open source camera and video app from Github, I do not have enough time to tell you the project I downloaded and used, but if you have time to ask me by posting comments here and sending me an email about it, I will tell you and would love to teach you.

I also learned about simple animation, hiding and showing some of my ui elements. You can see the tutorial in my next post, CLICK HERE.

Last, I discovered how to toggle the visibility of my tab bar programmatically. Check it out HERE.

I'm not going to cut this today's post. Please be sure to subscribe!

16th Day As An iOS Developer With No Experience



September 24, 2015 - 16th Day As An iOS Developer With No Experience.

Thursday - I had a talk with Ms. K, one of our Q.A in the office. She told me that our senior Ms. R. stayed at the company, stayed beside kind sir CTO years before the company became stable. She stayed here during the rough times, and now the company earns so much now. So much projects.

Anyway, what I have learned today (actually I learned this last night) is to use ImagePicker for video recording. And how to save it of course. Stay tune, subscribe, to check out my easy tutorials for newbies in the future. I just can't find some time to allocate for posting tutorials on this blog. How about when my company hires another iOS Developer? Okay, that will be a deal.

13th Day As An iOS Developer With No Experience



September 21, 2015 - 13th Day As An iOS Developer With No Experience

When I was searching for the open source app named “Aviary”, I stumbled upon this super cool open source iOS app made in Objective-C: CLImageEditor. I so love this. Oh, by the way, Isaw this Aviary from a certain iOS App, the app has implemented this Aviary (“Powered by Aviary).

While writing this post, I’m listening to Urbandub’s Endless, A Silent Whisper. Such cool song, a song about a rebel daughter lol. Anyway, I have been struggling in editing the open source app CLImageEditor, and I just realised that the documentation of the kind sires on Github about their open source projects are merely simple.

Simple enough for a noob like me to understand. How did I know? Of course I tried to read the documentation on how to use the CLImageEditor, here is an excerpt of the documentation:

INSTALLING: The easiest way to use CLImageEditor is to copy all the files in the CLImageEditor group (or directory) into your app. Add the following frameworks to your project (Build Phases > Link Binary With Libraries): Accelerate, CoreGraphics, CoreImage. Super simple, right?

Now I know, I need to try reading the documentation before complaining or before trying to implement and integrate the project to my project. The deadline is getting nearer and our CTO took some of our time, some of my time. He invited some of his team to go to dinner with him. Okay, thank you kind sir! :) He’s really generous.

 I have some backlogs needed to be done this Holiday (Friday - September 25). Some tutorials that will be linked to my September 18 post (12th Day). So I’m leaving now. Thanks for reading!