Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How and where to schedule local notification? Based on pushkit payload. #1

Closed
vishalkalola1 opened this issue Mar 31, 2017 · 1 comment
Assignees

Comments

@vishalkalola1
Copy link

I need your help to understand How and where to schedule local notification? Based on pushkit payload.

Kindly do suggest, possible with code.

@hasyapanchasara
Copy link
Owner

Well, once you receive push kit payload in it's delegate method didReceiveIncomingPushWithPayload, then you can schedule local notification or UserNotification from iOS 10 and above.

Below refer below code as reference to your question.

    func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
            // Process the received push
            
            var arrTemp = [NSObject : AnyObject]()
            arrTemp = payload.dictionaryPayload
            
            let dict : Dictionary <String, AnyObject> = arrTemp["aps"] as! Dictionary<String, AnyObject>
            
           
            if "IfUserHasLoggedInWithApp" // Check this flag then only proceed
            {                
                    
                if UIApplication.sharedApplication().applicationState == UIApplicationState.Background || UIApplication.sharedApplication().applicationState == UIApplicationState.Inactive
                {
                       
                    if "CheckForIncomingCall" // Check this flag to know incoming call or something else
                    {
                                
                        var strTitle : String = dict["alertTitle"] as? String ?? ""
                        let strBody : String = dict["alertBody"] as? String ?? ""
                        strTitle = strTitle + "\n" + strBody
                                
                        let notificationIncomingCall = UILocalNotification()
                                
                        notificationIncomingCall.fireDate = NSDate(timeIntervalSinceNow: 1)
                        notificationIncomingCall.alertBody =  strTitle
                        notificationIncomingCall.alertAction = "Open"
                        notificationIncomingCall.soundName = "SoundFile.mp3"
                        notificationIncomingCall.category = dict["category"] as? String ?? ""
                                
                        notificationIncomingCall.userInfo = "As per payload you receive"
                                
                        UIApplication.sharedApplication().scheduleLocalNotification(notificationIncomingCall)
                                
                        }
                        else
                        {
                            //  something else
                        }
                       
            }
        }
           
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants