Check if Push Notification is enabled

We had our own flow of app permissions to be presented through our UX. Push notification was one of the permissions. For an early and simple start, my requirement was to know if an app has the permission for push notification. I used following code:

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]

Result was different on simulator and real device. On simulator it always returned NO, while it worked well on device until iOS 10.

Next, the reliable way(example) that I learned and worked across was:

- (BOOL)isPushNotificationsEnabled {
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) {
        UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
        return (types & UIUserNotificationTypeAlert);
    }
    else {//Before iOS8
        UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        return (types & UIRemoteNotificationTypeAlert);
    }
}

iOS Location Services: Authorization

We may want to know about the permission for location services that is granted to the app. This is useful in many ways where you want to control the flow in your UX to show the permission at definite point of place.

General setting of location service may be OFF on device. First (optional) step would be to check if location service is ON/OFF for the device.

[CLLocationManager locationServicesEnabled]

If service is OFF/Disabled in device then you can ask for the permission based on your need:

[self.locationManager requestWhenInUseAuthorization]
[self.locationManager requestAlwaysAuthorization]

This will open default alert where user has the option to go directly to settings page of location service in a device, user can toggle service to ON/OFF, for the case where location is disabled in a device.

If location service is ON then it doesn’t mean that app has the permission to use the service. We need to check the authorisation status for the app.


[CLLocationManager authorizationStatus]

It returns the following authorization statuses:

typedef enum {
   kCLAuthorizationStatusNotDetermined = 0,
   kCLAuthorizationStatusRestricted,
   kCLAuthorizationStatusDenied,
   kCLAuthorizationStatusAuthorized,
   kCLAuthorizationStatusAuthorizedAlways = kCLAuthorizationStatusAuthorized,
   kCLAuthorizationStatusAuthorizedWhenInUse 
} CLAuthorizationStatus;

If user hasn’t given the permission yet, including denied permission, then we will get:
kCLAuthorizationStatusNotDetermined
Now we can make the permission request based on our type of need to bring the default native permission alert to the user.

[self.locationManager requestWhenInUseAuthorization]
[self.locationManager requestAlwaysAuthorization]

If user had previously denied by cancelling the permission alert then status will be kCLAuthorizationStatusDenied


In this situation we would like the app to redirect user to app’s settings in device. We may also like to show the alert manually where, once the permission is denied then default alert from iOS will not appear after asking for the permission in code, user will have the option to cancel or redirect to settings.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

Course of determination

Against the course,
Swimming upstream,
With a taste of every rub
In every gulp,
Determined to reach
Is the salmon inside me.

मार्ग विरुद्ध,
निर्गमन प्रवाह विपरीत पौडिरहेका,
हरेक चुनौती को एक स्वाद संग
हरेक सुडकना मा,
पुग्न कटिबद्ध छ
म भित्र सालमन माछा  ।

-Paddy

A photo posted by Padam Thapa (@padam_thapa) on

Kafka on the shore

After finishing the novel, for one whole day, I was high on the bizarre and outlandish union of mystique, ecstasy and melancholy.

padamthapa_kafka_on_the_shore_haruki_murakami

Kafka on the shore by Haruki Murakami

I have theories that connects the metaphors to the missing dots of the story plot and mysterious characters. I couldn’t resist writing about it for many people had hard time making sense of various designs. There are also obvious outlines that can be interpreted without giving much sweat. I would like to focus on the enigmatic and puzzling fragments of the story. For answers to a riddle a new riddle is formed. This new riddle could be a question or maybe a solution to the interpretation. Same thing happens with my theories. Answers will rise to new riddles.

  • Who was Johnny walker?
  • What is flute that he has been working on?
  • Why did Johnny walker wanted Nakata to kill him?
  • How did Nakata lost his all memories?
  • What does mysterious and mystique raining of objects from the sky denotes and how is it connected to Nakata?
  • What does showdown between boy named crow and Johnny walker means?

Everything starts from the rice bowl hill accident during world war 2. School and military authorities were perplexed by the accident of sudden mass hypnotization where children lost consciousness. In a novel author has focused on the existence of two parallel planes: conscious and unconscious. Human spirit could dwell between the two through a subconscious tunnel. In this case of accident for some unexplained phenomenon all students lost consciousness and it is during this state that their spirit crossed over to unconscious plane.

In the later progress of a novel an existence of a place is revealed which is separate from the reality where time doesn’t exist or matter. This place is some haven between life and death. There are two side effects of staying in this place for long which I derived from the plotline:

  • Your soul will be absorbed into the place.
  • All the memories will be lost.

Do you have memories?”

“No, I don’t. In a place where time isn’t important, neither is memory. Of course I remember last night, coming here and making vegetable stew. And you ate it all, didn’t you? The day before that I remember a bit of. But anything before that, I don’t know. Time has been absorbed inside me, and I can’t distinguish between one object and whatever’s beside it.

My theory of memory loss was derived from the explanation of 15 years old Miss Saeki to Kafka. I could deduce that too longer exposure in this place absorbs the spirit along with memories. Nakata was unconscious for weeks. That could be long enough for his spirit to lost the memories there. There is another conversation where young Miss Saeki tells about the period it takes to get fully absorbed.

How long will it take for me to get used to this place?”

“I have no idea. Its not a question of time. When that time comes, you’ll already be used to it.

Nakata spent long time here and when his spirit returned to conscious plane, it was only half of his spirit. Other half was absorbed into that place with his all memories. What remained of his spirit was some fragments.

I also deduced that absorbing of spirit meant dying slowly. We do not have a concept of heaven and hell. There is a place which separates life reality from afterlife or death. This place is accessed through an entrance whose search has been the focus of story.

When Nakata returned to consciousness, he lost his memory, and acquired the gift to converse with cats. I have a theory on this too and raising up more riddles. When Hoshino realized that he could talk to a cat named Toro, cat explained him something.

We’re on the border of this world, speaking a common language. That’s all.

This conversation is really important to understand the riddle of ability to talk with cats. Here border of this world could mean many thing and interpreted into various theories. My theory says that we are talking about the edge of the reality across which lies the unconscious plane or death. That small village can also be seen as some form of border. Cat also signifies something in more mystique or mythical sense. There was a movie Constantine starring Keanu reeves. There was a scene where he mentioned that cat are the medium between life-reality and death, and he performs the occult with the cat to travel across the reality to hell and back. Of course there maybe not much connection but I could really think that cats are some special creature that shares this border between reality and across. Toro had said:

Cats know everything

So my conclusion from this derivation was that Nakata’s half spirit was already absorbed into that small village which is another form of border that divides life and death, so he could talk to cats. My big hunch is that cats are special based on Constantine’s Myth theory. This raises a question on the ability of Noshino to talk with cats. Did Noshino reached border?

Johnny walker is an evil spirit but he explains to Nakata that he is beyond good and evil. In this world he has a role to fulfil and tasks to perform. His role in this reality has been to acquire the souls. Now he has got tired of this task and wants to be dead and leave this reality. This reminds me of Mr. Smith from a movie The Matrix. Again there is no concept of hell and heaven but just a reality and after-life. Johnny wants to take off for that afterlife. But there is restriction for him to achieve that. His only chance is through the entrance gate. This will be explained further. He found Nakata. He could understand that Nakata is the person with whose help he can leave this world. He had mentioned about theories he had regarding Nakata. He never revealed what those theories were but he was very sure that Nakata is the person that he has been looking for a while. I think Johnny deduced the theories from Nakata’s ability to talk to cats and his partial shadow. Johnny is a form or spirit, not a normal human, so we can also assume that he knows that someone who is at the border of this world only can talk to the cats and his theory backed up by Nakata’s partial shadow. Only way to leave this plane was to get killed by this person with some rules. Nakata kills Johnny in the end. Why Nakata has to kill him? It will get more clear down the path.

After bizarre accident with Johnny, Nakata mysteriously found himself back on vacant plot of land. He realizes that he no longer can talk to cats. In police station when his confession was rebuked, he forecasted a rain of fish and sardines. Later in the story there occurs a rain of leeches too. Many readers were puzzled over this including me. To have some kind of reason for closure I searched for a theory and found one. My theory again could be some bogus drivel. Later through the flow of a story I had found or came to conclusion that Johnny walker and Kafka’s father are same, the outer body shell at least. Kafka also has regarded his father to be evil. He made a prophecy about Kafka. I connected this dot to Nakata. I realized that weather forecasting is also some form of prophecy. There was a missing state of consciousness and time after the murder of Johnny. What immediately exactly happened after that is a puzzle. My belief is that Johnny absorbed himself into Nakata. His form or spirit was hiding inside the Nakata now. This theory will be more clear further so have some patience. Whole process of murder was to achieve this: Getting inside Nakata. When this happened, Nakata gained the power of some form of prophecy to rain. I was more sure about this because towards the end an evil form was squirming out of Nakata’s mouth. Noshino pondered:

Was it some sort of parasite that had been hiding inside Nakata all this time?

My conclusion was yes. This parasite was hiding inside Nakata. This parasite was Johnny walker. Johnny was hiding inside Nakata because he knew Nakata will be searching for entrance stone to unite with his lost shadow. Later it is revealed that unification happens on the other side. Nakata died at noon so why didn’t Johnny came out and get in through the entrance gate while it was open? Toro the cat told Hoshino that – “It” makes a move very late at night.

Nakata and Kafka are connected to each other through two points: Crow and Johnny. There is a chapter where Crow attacks Johnny in some plane of limbo. This chapter is very interesting and helps to interpret many things and solidifies my theory of Johnny inside Nakata more. Johnny hasn’t reached afterlife yet. He is hiding inside Nakata and is in Limbo. Torro had told Noshino: “You have to kill it” to bring everything to original. Crow knew this for which he attacked Johnny. It was fruitless. It is the same Crow who reveals to Kafka throughout the story. I conclude that Crow is a spirit. Johnny is waiting for the night to enter through entrance. In finale, entrance is closed and Johnny is killed by Noshino.

The boy named Crow is the mysterious one. I am thinking he is the other half spirit of Nakata so far. Crow is a boy and Nakata lost his memories with one half spirit when he was a boy. Crow is waiting to become whole with other half that is dwelling in reality with Nakata. That is fulfilled in the end as Noshino concludes that only place for unification was across the reality. Only missing dot is the relation between Crow and Kafka.

Lastly, there was a lightning accident where Kafka’s father eluded the strike by mere moments but his friends fate wasn’t auspicious. It was after this accident that Kafka’s father changed. I am thinking this was the juncture where Johnny walker came into being.

Kafka, Miss Saeki’s background isn’t too complicated but not uncomplicated too. Yes that is how Murakami’s novels are. I won’t indulge in the explanation about them. If you think my theories on Nakata and Johnny makes little much sense then Kafka’s and Miss Saeki’s mysteries can be derived from it or you can add more of your flavor. Novel also focuses on the split of living spirit and its body so think around this too. In the end everyone has their own interpretation and you should enjoy it rather than cussing Murakami. Go deeper and avoid wading the shallow creek.