Tejaswi iitv Tejaswi iitv - 1 month ago 13
iOS Question

What is Push Notification and how to get chat notification in ios?

I need help regarding push notification for chat application.I am not having any idea about that push notification and all.To show notification while chatting that is used or anything other in ios.Please help me out.

Answer

Try this. It works for me.

Fist I having to explain you about Push Notification

1) Push Notification Overview

enter image description here

1) An app enables push notifications.The user has to confirm that he wishes to receive these notifications.

2)The app receives a “device token”. You can think of the device token as the address that push notifications will be sent to.

3)The app sends the device token to your server.

4)When something of interest to your app happens, the server sends a push notification to the Apple Push Notification Service, or APNS for short.

5)APNS sends the push notification to the user’s device.

2) Coding for Push Notification

In AppDelegate.m call following delegates methods.

1) Registered for push Notification

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
  {
//-- Set Notification
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
   {

    // iOS 8 Notifications
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

     [application registerForRemoteNotifications];
   }
  else
  {
    // iOS < 8 Notifications
    [application registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}

//--- your custom code
return YES;
 }

2)For Device Token

   - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
 {
   NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"%@", token);

}

3)Receive Push Notification

  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  {
 NSLog(@"Received notification: %@", userInfo);
 }

Follow above process for push notification and refer this tutorial for details Push Notification working tutorial

3)Chat Application by using Push Notification

For Chat application you use either your own server or use third party API like QiuckBlox Refer this SDK for chat application . https://github.com/QuickBlox/quickblox-ios-sdk/tree/master/sample-chat

Also refer chat application tutorial in detail. http://quickblox.com/developers/SimpleSample-chat_users-ios

Comments