#Blog

Blog articles on programming and problems focused on iOS and some web. I also write stories on my travel and hiking pursuits outside my work.

How to Display Image in SKShapeNode

by

I have been using SKShapeNode extensively to draw quick graphics by filling them with CGPaths for quick visual debugging and making prototypes. For example I can create procedural mountains quickly with SKShapeNode. In early times of spritekit SKShapeNode didn’t have way to render images on it. We have fillTexture available now that allows texture to fill the shape.


let shapeNode = SKShapeNode()
shapeNode.fillTexture = SKTexture(imageNamed: “testImage")

But, Our SKShapeNode is displaying nothing.

Why is that?

CONTINUE READING


App crashing when saving photos from WKWebView

by

I stumbled upon a crash in my app. In my app I have a WKWebView that lets user access web. I tried saving image from a website by long pressing - general way we do in our iOS safari - and app crashed. This user experience behaviour of long pressing and saving image is very common.

The crash error is:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data.

CONTINUE READING


UIImagepicker controller allowsEditing not working

by

Using native image picker system is easy and solves everyday basic needs of most apps.

UIImagePickerController
A view controller that manages the system interfaces for taking pictures, recording movies, and choosing items from the user’s media library.

Here is an example code that lets user pick images from photo library:


pickerController = UIImagePickerController()
pickerController?.delegate = self
pickerController?.mediaTypes = [“public.image”]
pickerController?.sourceType = .photoLibrary
self.present(pickerController!, animated: true, completion: nil)

We need to implement delegate methods that provides us media info from which we can extract image in our case if available. Here is a code


func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    if let image = info[.originalImage] as? UIImage{
    }
}

info
A dictionary containing the original image and the edited image, if an image was picked; or a filesystem URL for the movie, if a movie was picked. The dictionary also contains any relevant editing information. The keys for this dictionary are listed in Editing Information Keys.

Our picked image resides inside the key .originalImage which is optional so if something went wrong then it will be nil.

Now, UIImagePickerController also supports basic crop. To activate crop we set the allowsEditing property to true. By default it is false.

CONTINUE READING


Amanita Caesarea: Hunting Edible Caesar's Mushroom

by


I went outdoors to forest in hills of Nepal to forage mushrooms and identify them. Monsoon has announced its presence and marks the season for some edible mushrooms from Amanita family to be found in wild. Amanita is tricky family and recommended to avoid by non-experienced mushroom foragers. We were looking for mainly edible Caesar’s Mushrooms or Amanita Caesarea. There are poisonous imposters so be careful and be 100% sure.



I am an inexperienced mushroom forager beginner with no experience in mushroom identification. This marked my first field experience in identifying wild mushrooms. I brought along my mother who has some experience in identifying edible mushrooms - mainly caesar’s mushroom. Right now, Forest is lush green and so fresh like springtime of youth from monsoon rains and making appearances of Amanita mushrooms that is common native to this nearby region during from months of June to August.

CONTINUE READING


How to redirect HTTP to HTTPS in Elastic Beanstalk

by

I want to configure the web servers on my Elastic Beanstalk environment’s instances to redirect HTTP traffic to HTTPS.

I want to state what my beanstalk environment is:

  • Apache Web Server.
  • PHP 7.3
  • HTTPS listener well configured with certificate

I will use a flexible way to configure my environment using .ebextensions

According to documentation:
You can add AWS Elastic Beanstalk configuration files (.ebextensions) to your web application's source code to configure your environment and customize the AWS resources that it contains. Configuration files are YAML- or JSON-formatted documents with a .config file extension that you place in a folder named .ebextensions and deploy in your application source bundle.
CONTINUE READING


AWS Elastic Beanstalk Swap Environment Urls

by

AWS provides a feature to exchange or swap the CNAME between environments. Documentation says -

CNAME swap

Because AWS Elastic Beanstalk performs an in-place update when you update your application versions, your application can become unavailable to users for a short period of time. You can avoid this downtime by performing a blue/green deployment, where you deploy the new version to a separate environment, and then swap CNAMEs of the two environments to redirect traffic to the new version instantly. A blue/green deployment is also required when you want to update an environment to an incompatible platform version.

If I want to upgrade my elastic beanstalk platform from say - for example php 5.6 to php 7.1 - then unfortunately I cannot do it. It allows me to upgrade within 5.6 platform but not switch between major platforms. Only recommended way is to create new environment with major upgraded platform and then swap the environment urls. This way original environment url will still be pointed to my domain running new platform.

CONTINUE READING


HTTPS not working on AWS Elastic Beanstalk

by

Adding HTTPS to elastic beanstalk environment isn’t complicated to configure; until I fell into small mistake. Some of configuration dashboard’s flow been changed a bit from last time I setup the SSL certificate to a beanstalk environment.

Assumptions:

  • SSL certificate is ready from AWS Certificate manager.
  • Using lassic Load Balancer (Optional)
  • Configuration on application side is all fine.

Now assumption is we already have a SSL certificate created from AWS Certificate manager. We will head inside configuration of beanstalk environment. Under Load Balancer Configuration, we will add new lister that listens to HTTPS protocol at port 443. Under the settings, HTTP listener will already be added by default. Another assumption is that default security group added during creation of environment has all correct inbound rules to allow proper incoming access. Generally this is all taken care by beanstalk environment behind the scenes so we will not delve into too deep but focus on abstraction layer where making a mistake is easily susceptible to a new user.

CONTINUE READING


How to Get Substring With NSRange in Swift 5

by


Warning:

substring(with:)’ is deprecated: Please use String slicing subscript.

In Swift 5 we do no longer have access to substring() methods for they are deprecated. We will discuss all alternatives and understand them in details.

  • How to access Characters in String?
  • Why Int based Subscript is not available in Swift?
  • What is difference between Range and NSRange?
  • How does String Indices work?
  • How to create Range from String Indices?
  • How to get substring with Range?
  • How to get substring with NSRange?

CONTINUE READING


How to Fix Warning Attempt To Present UIAlertController in Swift

by

Warning: Attempt to present <UIAlertController: 0x7fa95080de00> on <MainViewController: 0x7fa94f8a5000> which is already presenting (null)

Warning of attempt to present view controller is common occurrence when making an easily made mistake. I will take Alert controller for an example to discuss.

Lets’s create a scenario to bring UIAlertController warning message and observe side effect to understand our situation more effectively. Then we will understand on how to fix warning attempt to present UIAlertController. I will present a Detail view controller modally from Main controller, and Main controller will be delegate object assigned to the property of Detail view controller. In our presented view controller I have a dismiss code when back button is pressed. Before dismissing the controller I will call the delegate object - Main controller in this case - to present Alert controller from Main controller.

CONTINUE READING


Mailto: Email Link Tricks in HTML

by

We use mailto links in html that opens default mail client app in the system. Mailto takes parameters that helps to create message with relevant fields already filled out for us.

But here’s the kicker: How do we create email message with all relevant fields filled out but without recepient name? We want user to fill recepient manually.

Now: First let’s see how mailto link is constructed -


<a href=“mailto:recepient@email.com?cc=first@email.com, second@email.com&bcc=gossip@email.com&subject=blah”>
Email Us
</a>

Common Mailto components are:

mailto:recepient@email.comRecipient address
cc=name@email.comCarbon copy e-mail address
bcc=name@email.comBlind carbon copy e-mail address
subject=subject textSubject of e-mail
body=body textBody of e-mail
?First paramter delimeter
&other parameters delimiter

Now comes the best part:

CONTINUE READING


Recommended posts