php - In ios 8 push notification not showing me badges for current app -
hello friends new in push notification please me out. trying badge count app "nsdictionary userinfo" contains alert , sound . code register device push notification
-(bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { if ([[uiapplication sharedapplication] respondstoselector:@selector(registerusernotificationsettings:)]) { uiusernotificationsettings* notificationsettings = [uiusernotificationsettings settingsfortypes:uiusernotificationtypebadge |uiusernotificationtypealert | uiusernotificationtypesound categories:nil]; [[uiapplication sharedapplication] registerusernotificationsettings:notificationsettings]; [[uiapplication sharedapplication] registerforremotenotifications]; } else { [[uiapplication sharedapplication] registerforremotenotificationtypes: (uiremotenotificationtypebadge | uiremotenotificationtypealert | uiremotenotificationtypesound)]; }
now
when message server.
-(void)application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo { nslog(@"%@",userinfo); if (application.applicationstate == uiapplicationstateactive) { /***********code show alert********/ if (![[[nsstring alloc]initwithstring:[[userinfo objectforkey:@"aps"] objectforkey: @"alert"]] isequaltostring:@""] && [[nsstring alloc]initwithstring:[[userinfo objectforkey:@"aps"] objectforkey: @"alert"]]!=nil) { nsstring *msg =[[nsstring alloc]initwithstring:[[userinfo objectforkey:@"aps"] objectforkey: @"alert"]]; uialertview *alert = [[uialertview alloc]initwithtitle:@"message" message:msg delegate:nil cancelbuttontitle:@"okay" otherbuttontitles:nil, nil]; [alert show]; } else { uialertview *alert = [[uialertview alloc]initwithtitle:@"message" message:@"notification received." delegate:nil cancelbuttontitle:@"okay" otherbuttontitles:nil, nil]; [alert show]; } } application.applicationiconbadgenumber =[[[userinfo objectforkey:@"aps"] objectforkey: @"badge"]integervalue]; if (userinfo) { nslog(@"%@",userinfo); if ([userinfo objectforkey:@"aps"]) { if([[userinfo objectforkey:@"aps"] objectforkey:@"badgecount"]) { [uiapplication sharedapplication].applicationiconbadgenumber = [[[userinfo objectforkey:@"aps"] objectforkey: @"badgecount"] intvalue]; } } } }
now output
{ aps = { alert = "magic 2 salon app!"; sound = default; }; }
my php code `
// put device token here (without spaces): $devicetoken = 'xxxxxxxxx'; // put private key's passphrase here: $passphrase = 'xxxxxx'; // put alert message here: $message = 'xxxxxxx!'; $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); // open connection apns server $fp = stream_socket_client( 'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, stream_client_connect|stream_client_persistent, $ctx); if (!$fp) exit("failed connect: $err $errstr" . php_eol); echo 'connected apns' . php_eol; // create payload body $body['aps'] = array( 'alert' => $message, 'sound' => 'default' ); // encode payload json $payload = json_encode($body); // build binary notification $msg = chr(0) . pack('n', 32) . pack('h*', $devicetoken) . pack('n', strlen($payload)) . $payload; // send server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) echo 'message not delivered' . php_eol; else echo 'message delivered' . php_eol; // close connection server fclose($fp);`
there no problem ios code far, in php script missing badge count.
in ios apps, unread notification counts maintained backend/server. when backend/server sends push notification particular device server sends badge count along payload.
so guess end not sending badge count.
the backend/server team should follow format, can badge count programatically:-
{ "aps" : { "alert" : "msg", "badge" : 1 , "sound" : "demo.aiff" } }
here tutorial link, how add badge count in php script:-
http://b2cloud.com.au/tutorial/ios-push-notifications-in-php/
http://learn-php-by-example.blogspot.in/2013/01/working-with-apple-push-notification.html
Comments
Post a Comment