ios - didReceiveRemoteNotification not called Swift -
for reason didreceiveremotenotification never called. have done following:
checklist of apns:
create appid allowed push notification
create ssl certificate valid certificate , app id
create provisioning profile same certificate , make sure add device
with code:
register app push notification
handle didregisterforremotenotificationswithdevicetoken method
set targets> capability> background modes> remote notification handle didreceiveremotenotification
yet function not seem called. code looks this:
func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { // override point customization after application launch. if (application.respondstoselector("isregisteredforremotenotifications")) { // ios 8 notifications application.registerusernotificationsettings(uiusernotificationsettings(fortypes: (.badge | .sound | .alert), categories: nil)); application.registerforremotenotifications() } else { // ios < 8 notifications application.registerforremotenotificationtypes(.badge | .sound | .alert) } return true } func application(application: uiapplication, didregisterforremotenotificationswithdevicetoken devicetoken: nsdata) { let tokenchars = unsafepointer<cchar>(devicetoken.bytes) var tokenstring = "" var = 0; < devicetoken.length; i++ { tokenstring += string(format: "%02.2hhx", arguments: [tokenchars[i]]) } apnsid = tokenstring println("******apnsid \(apnsid)") dtoken = devicetoken println("******dtoken \(dtoken)") nsuserdefaults.standarduserdefaults().setobject(devicetoken, forkey: "devicetoken") } func application(application: uiapplication, didfailtoregisterforremotenotificationswitherror error: nserror) { println("***********didfailtoregisterforremotenotificationswitherror") println(error) } func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject], fetchcompletionhandler completionhandler: (uibackgroundfetchresult) -> void) { println("getting notification") var message: nsstring = "" var alert: anyobject? = userinfo["aps"] println(userinfo["aps"]) if((alert) != nil){ var alert = uialertview() alert.title = "title" alert.message = "message" alert.addbuttonwithtitle("ok") alert.show() } }
Comments
Post a Comment