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

Parse Dashboard Delivery Report is 0 for send and receive messages #3750

Closed
aBuder opened this issue Apr 25, 2017 · 10 comments
Closed

Parse Dashboard Delivery Report is 0 for send and receive messages #3750

aBuder opened this issue Apr 25, 2017 · 10 comments

Comments

@aBuder
Copy link

aBuder commented Apr 25, 2017

No description provided.

@aBuder
Copy link
Author

aBuder commented Apr 25, 2017

Hi,

if I send an message from parse dashboard, the push notification receives on iOS. I see the notification, but in dashboard the sent and deliver is 0.

How I can fix that?

bildschirmfoto 2017-04-25 um 08 22 42

import UIKit
import UserNotifications
import Parse

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        // ****************************************************************************
        // Initialize Parse SDK
        // ****************************************************************************
        let configuration = ParseClientConfiguration {
            $0.applicationId = "ParsePlayground"
            $0.server = "https://whispering-spire-56438.herokuapp.com/parse"
            $0.isLocalDatastoreEnabled = true
        }
        
        Parse.initialize(with: configuration)
        
        if PFUser.current() == nil {
            print("no current user set")
            self.showLoginViewController()
        } else {
            print("current user set")
        }
        
        let defaultACL = PFACL()
        
        // If you would like all objects to be private by default, remove this line.
        defaultACL.getPublicReadAccess = true
        
        PFACL.setDefault(defaultACL, withAccessForCurrentUser: true)
        
        
        if let currentUser = PFUser.current() {
            PFInstallation.current()?.setObject(currentUser, forKey: "user")
        }
        
        let notificationCenter = UNUserNotificationCenter.current()
        notificationCenter.delegate = self
        notificationCenter.requestAuthorization(options: [.alert, .sound, .badge]) {
            (granted, error) in
            if error == nil{
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
        

        
        // Override point for customization after application launch.
        return true
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content.userInfo
        print("User Info = ", userInfo)
        PFPush.handle(userInfo)
        PFAnalytics.trackAppOpened(withRemoteNotificationPayload: userInfo)
        completionHandler([.alert, .badge, .sound])
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo

        print("User Info = ", userInfo)

    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


    //--------------------------------------
    // MARK: Push Notifications
    //--------------------------------------
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let installation = PFInstallation.current()
        installation?.setDeviceTokenFrom(deviceToken as Data)
        installation?.saveInBackground()
    }
    
    private func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
        if error.code == 3010 {
            print("Push notifications are not supported in the iOS Simulator.\n")
        } else {
            print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error)
        }
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        PFPush.handle(userInfo)
        application.applicationIconBadgeNumber = 0;
        PFAnalytics.trackAppOpened(withRemoteNotificationPayload: userInfo)
    }
    
    /**
     Zeigt LoginViewController
    */
    public func showLoginViewController() {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let loginViewController = storyboard.instantiateViewController(withIdentifier: "LoginViewController")
        self.window?.rootViewController = loginViewController
    }
    
    /**
     Zeigt RegisterViewController
     */
    public func showRegisterViewController() {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let registerViewController = storyboard.instantiateViewController(withIdentifier: "RegisterViewController")
        self.window?.rootViewController = registerViewController
    }
    
    /**
     Zeigt MainTabBarController
    */
    public func showMainTabBarViewController() {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let mainTabBarController = storyboard.instantiateViewController(withIdentifier: "MainTabBarController")
        self.window?.rootViewController = mainTabBarController
    }  
}

@flovilmart
Copy link
Contributor

Can you provide the logs when running VERBOSE=1 ?

@brianyyz
Copy link

brianyyz commented May 17, 2017

I am having the same problem. I am able to successfully send a push to an IOS device however the Parse Dashboard reports 0 sent. Parse Server 2.4.0 is running on Heroku and the parse-server-push-adapter is 1.3.0

I created the push through the dashboard by specifying IOS devices and a specific user objectId.

The log output with VERBOSE=1 follows (I've flagged two lines in bold that I've not seen before):

2017-05-17T19:39:58.311430+00:00 heroku[router]: at=info method=POST path="/parse/push" host=murmuring-meadow-91837.herokuapp.com request_id=0df0a61e-e467-4a05-888e-4fca92a904b0 fwd="158.57.45.68" dyno=web.1 connect=0ms service=41ms status=200 bytes=533 protocol=https
2017-05-17T19:39:58.278750+00:00 app[web.1]: verbose: REQUEST for [POST] /parse/push: {
2017-05-17T19:39:58.278791+00:00 app[web.1]: "where": {
2017-05-17T19:39:58.278792+00:00 app[web.1]: "user": {
2017-05-17T19:39:58.278793+00:00 app[web.1]: "__type": "Pointer",
2017-05-17T19:39:58.278794+00:00 app[web.1]: "className": "_User",
2017-05-17T19:39:58.278794+00:00 app[web.1]: "objectId": "4SyoikWoDH"
2017-05-17T19:39:58.278795+00:00 app[web.1]: },
2017-05-17T19:39:58.278796+00:00 app[web.1]: "deviceType": {
2017-05-17T19:39:58.278796+00:00 app[web.1]: "$in": [
2017-05-17T19:39:58.278797+00:00 app[web.1]: "ios"
2017-05-17T19:39:58.278798+00:00 app[web.1]: ]
2017-05-17T19:39:58.278798+00:00 app[web.1]: }
2017-05-17T19:39:58.278799+00:00 app[web.1]: },
2017-05-17T19:39:58.278800+00:00 app[web.1]: "data": {
2017-05-17T19:39:58.278800+00:00 app[web.1]: "alert": "Hello Brian"
2017-05-17T19:39:58.278801+00:00 app[web.1]: }
2017-05-17T19:39:58.278803+00:00 app[web.1]: } method=POST, url=/parse/push, host=murmuring-meadow-91837.herokuapp.com, connection=close, user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0, accept=/, accept-language=en-US,en;q=0.5, accept-encoding=gzip, deflate, br, content-type=text/plain, referer=http://localhost:8080/apps/3.%20Rides%20Heroku%20Prod/push/new, origin=http://localhost:8080, dnt=1, x-request-id=0df0a61e-e467-4a05-888e-4fca92a904b0, x-forwarded-for=158.57.45.68, x-forwarded-proto=https, x-forwarded-port=443, via=1.1 vegur, connect-time=0, x-request-start=1495049998268, total-route-time=0, content-length=344, __type=Pointer, className=_User, objectId=4SyoikWoDH, $in=[ios], alert=Hello Brian
2017-05-17T19:39:58.282122+00:00 app[web.1]: warn: Trying to schedule a push while server is not configured.
2017-05-17T19:39:58.284218+00:00 app[web.1]: warn: Push will be sent immediately
2017-05-17T19:39:58.308640+00:00 app[web.1]: verbose: RESPONSE from [POST] /parse/push: {
2017-05-17T19:39:58.308645+00:00 app[web.1]: "headers": {
2017-05-17T19:39:58.308646+00:00 app[web.1]: "X-Parse-Push-Status-Id": "CcevIoiLO0"
2017-05-17T19:39:58.308647+00:00 app[web.1]: },
2017-05-17T19:39:58.308647+00:00 app[web.1]: "response": {
2017-05-17T19:39:58.308648+00:00 app[web.1]: "result": true
2017-05-17T19:39:58.308648+00:00 app[web.1]: }
2017-05-17T19:39:58.308649+00:00 app[web.1]: } X-Parse-Push-Status-Id=CcevIoiLO0, result=true
2017-05-17T19:39:58.320512+00:00 app[web.1]: verbose: _PushStatus CcevIoiLO0: sending push to 2 installations
2017-05-17T19:39:58.689166+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Connected
2017-05-17T19:39:58.794468+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Notification transmitted to 005341c0a971ac4f15fa8e1e91aafa8f1c03ceb53c69a1f7210c3992880db84e
2017-05-17T19:39:58.796892+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Notification transmitted to 759ed61e1b3af571f09cd3b667c40c63fc17273adc127e96643c061df4a08b6a
2017-05-17T19:39:58.799361+00:00 app[web.1]: verbose: _PushStatus CcevIoiLO0: sent push! 0 success, 0 failures

Let me know if you need more details. This problem does not occur on pushes sent from my local parse-server where parse-dashboard correctly reports the number of pushes sent.

EDIT
My local server is running parse-server 2.3.2 and pointing to Sandbox APNS
My Heroku server is running parse-server 2.4.0 and pointing to Production APNS

2nd EDIT
Regressed Heroku server to 2.3.2 and dashboard now correctly reports number of push notifications sent.

@brianyyz
Copy link

Bump.

@wiselyku
Copy link

wiselyku commented Jun 21, 2017

hi guys,
We also have the same problem.
Can anyone help us?

@FarisAlbalawi
Copy link

Here is the solution of this problem - just add this code to home view

override func viewDidAppear(_ animated: Bool) {
    // Associate the device with a user for Push Notifications
    if PFUser.current() != nil {
        let installation = PFInstallation.current()
        installation?["username"] = PFUser.current()!.username
        installation?["userID"] = PFUser.current()!.objectId!
        installation?.saveInBackground(block: { (succ, error) in
            if error == nil {
                print("PUSH REGISTERED FOR: \(PFUser.current()!.username!)")
        }})
    }
    
}

@flovilmart
Copy link
Contributor

Can you update to the latest version? A lot has changed and was fixed in the latest versions for pushes.

@aBuder
Copy link
Author

aBuder commented Feb 9, 2018

@flovilmart I would try it the next days.

@billyz313
Copy link

Did anyone find a solution for this?

@stale
Copy link

stale bot commented Sep 18, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

6 participants