phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

Registration but no Notification iOS, XCode 8.3.2, phonegap 1.10.2 #1691

Closed toddtsic closed 7 years ago

toddtsic commented 7 years ago

Details:

Previously Android/iOS both working on XCode 8.0.0, phonegap 1.8.4 until I learned iOS 10 users not receiving notifications.

Updgraded to XCode 8.3.2, phonegap 1.10.2 ==> Android fine, iOS registers but doesn't notify for iOS 9.3, and 10.3 (my test devices).

XCode console showing successfull registration:

2017-04-24 14:47:34.334 TSICMobile[4068:4133708] Push Plugin register called
2017-04-24 14:47:34.335 TSICMobile[4068:4133708] PushPlugin.register: setting badge to false
2017-04-24 14:47:34.335 TSICMobile[4068:4133708] PushPlugin.register: clear badge is set to 0
2017-04-24 14:47:34.336 TSICMobile[4068:4133708] PushPlugin.register: better button setup
2017-04-24 14:47:34.337 TSICMobile[4068:4133708] GCM Sender ID (null)
2017-04-24 14:47:34.337 TSICMobile[4068:4133708] Using APNS Notification
2017-04-24 14:47:34.372 TSICMobile[4068:4133644] Push Plugin register success: <006bc64f 7e216d2d 87dc2f50 fbe9eb06 905e08f9 0ae749b5 5e16e458 b7e38f31>
2017-04-24 14:47:34.669 TSICMobile[4068:4133644] 006bc64f7e216d2d87dc2f50fbe9eb06905e08f90ae749b55e16e458b7e38f31
2017-04-24 14:47:34.669 TSICMobile[4068:4133644] DEBUG Device LATESTDEVICEID: BE16E1C7-3E85-44F3-8694-F3BCAAEC6D01
2017-04-24 14:47:34.670 TSICMobile[4068:4133644] DEBUG Device DEVICEID: BE16E1C7-3E85-44F3-8694-F3BCAAEC6D01
2017-04-24 14:47:34.670 TSICMobile[4068:4133644] DEBUG device TOKEN: 006bc64f7e216d2d87dc2f50fbe9eb06905e08f90ae749b55e16e458b7e38f31
2017-04-24 14:47:34.670 TSICMobile[4068:4133644] DEBUG device TYPE: ios

Action Taken: Remade apn certificates (used fastlane pem)

Testing:

Test Results: Both devices receive notification (and I can trap in debugger in the on.Notification section of the ionic service (code below)).

Of note, only way I can fail at pushtry.com is if I check "production" checkbox.

XCode console for successfull receipt of push test from pushtry.com:

    2017-04-24 14:47:49.307 TSICMobile[4068:4133644] didReceiveNotification with fetchCompletionHandler
    2017-04-24 14:47:49.307 TSICMobile[4068:4133644] app active
    2017-04-24 14:47:49.307 TSICMobile[4068:4133644] Notification received
    2017-04-24 14:47:49.308 TSICMobile[4068:4133644] Push Plugin key: badge
    2017-04-24 14:47:49.308 TSICMobile[4068:4133644] Push Plugin key: sound
    2017-04-24 14:47:49.308 TSICMobile[4068:4133644] Push Plugin key: alert
    2017-04-24 14:47:49.498 TSICMobile[4068:4133644] test-04
    2017-04-24 14:47:49.499 TSICMobile[4068:4133644] 1
    2017-04-24 14:47:49.499 TSICMobile[4068:4133644] default
    2017-04-24 14:47:49.500 TSICMobile[4068:4133644] {"foreground":true,"coldstart":false}

Ionic2 app is served by asp.net core web api site (c# code below)

Posts in c# are sent to APNS using host: api.push.apple.com port: 2197 cert: fastlane pem created production .p12

(Have also tried host: api.development.push.apple.com and fastlane pem created development .p12, both scenarios result in successful registration (evidenced by XCode console), and both fail to trap on.notification (with app in background or in foreground))

My gut is telling me that it has to be a payload formatting issue...

I'm dead in the water if I can't support iOS10, greatful for any assistance...

Cordova and Ionic details:

$ cordova -version
6.5.0

$ cordova plugins list
cordova-plugin-camera 2.4.0 "Camera"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-file 4.3.2 "File"
cordova-plugin-file-transfer 1.6.2 "File Transfer"
cordova-plugin-inappbrowser 1.7.0 "InAppBrowser"
cordova-plugin-media-capture 1.4.2 "Capture"
cordova-plugin-splashscreen 4.0.2 "Splashscreen"
cordova-plugin-statusbar 2.2.1 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-plugin-x-socialsharing 5.1.7 "SocialSharing"
cordova-sqlite-storage 2.0.3 "Cordova sqlite storage plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"
mx.ferreyra.callnumber 0.0.2 "Cordova Call Number Plugin"
phonegap-plugin-push 1.10.2 "PushPlugin"

$ cordova platform version
Installed platforms:
  ios 4.3.1
Available platforms:
  amazon-fireos ~3.6.3 (deprecated)
  android ~6.1.1
  blackberry10 ~3.8.0
  browser ~4.1.0
  firefoxos ~3.6.3
  osx ~4.0.1
  webos ~3.7.0

$ ionic info
Your system information:
Cordova CLI: 6.5.0
Ionic Framework Version: 2.0.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.0
ios-deploy version: 1.9.1
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v6.10.0
Xcode version: Xcode 8.3.2 Build version 8E2002

Ionic ConfigurePush():

    ConfigurePush() {
        if (!environment.production) {
            console.log('ConfigurePush: Start');
            console.log('isIOS:' + this.platform.is('ios'));
            console.log('isANDROID:' + this.platform.is('android'));
        }
        if (!this.platform.is('core') && !this.platform.is('mobileweb')) {
            let push = Push.init({
                android: {
                    senderID: environment.googleProjectNumber
                },
                ios: {
                    alert: 'true',
                    badge: 'true',
                    sound: 'true'
                },
                windows: {}
            });

            push.on('registration', (data) => {
                console.log(data.registrationId);
                let thisDeviceId = Device.uuid;

                let devType: string;
                if (this.platform.is('android')) {
                    devType = 'android'
                } else if (this.platform.is('ios')) {
                    devType = 'ios';
                }

                const deviceViewModel: DeviceViewModel = {
                    DeviceId: Device.uuid,
                    DeviceToken: data.registrationId,
                    DevType: devType,
                    LatestDeviceId: thisDeviceId
                }
                if (!environment.production) {
                    console.log('DEBUG Device LATESTDEVICEID: ' + deviceViewModel.LatestDeviceId);
                    console.log('DEBUG Device DEVICEID: ' + deviceViewModel.DeviceId);
                    console.log("DEBUG device TOKEN:", deviceViewModel.DeviceToken);
                    console.log("DEBUG device TYPE:", deviceViewModel.DevType);
                }

                this.pushService.setDeviceDetails(deviceViewModel);
                this.pushService.UpdateServerWithDeviceDetails(deviceViewModel);
            });

            push.on('notification', (data) => {
                let confirmAlert = this.alertCtrl.create({
                    title: data.title,
                    message: data.message.replace(/\n/g, '<br />'),
                    buttons: [{
                        text: 'Close',
                        role: 'cancel'
                    }
                    ]
                });
                confirmAlert.present(confirmAlert);

                if (!environment.production) {
                    console.log(data.message);
                    console.log(data.title);
                    console.log(data.count);
                    console.log(data.sound);
                    console.log(data.image);
                    console.log(data.additionalData);
                }

                push.finish(function() {
                    console.log("processing of push data is finished");
                }, function() {
                    console.log("something went wrong with push.finish for ID = " + data.additionalData.notId)
                }, data.additionalData.notId);
                });

            push.on('error', (e) => {
                console.log('PUSH ERROR: ' + e.message);
            });
        }

c# code calling APNS:

        private async Task<IActionResult> SendPushNotificiation_IOS(PushNotification_Ios pn, List<string> device_ids)
        {
            int port = Convert.ToInt32(_configuration["Push:IOS_APNS_URL_PORT"]);
            string hostname = _configuration["Push:IOS_APNS_URL"];
            string iosCertificatePath = String.Format("{0}\\{1}", _hostingEnvironment.WebRootPath, _configuration["Push:IOS_PATH_TO_P12_CERT"]);

            X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(iosCertificatePath), _configuration["Push:IOS_CERT_PASSWORD"]);
            X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);

            TcpClient client = new TcpClient(AddressFamily.InterNetwork);
            await client.ConnectAsync(hostname, port);

            SslStream sslStream = new SslStream(
                client.GetStream(), false,
                new RemoteCertificateValidationCallback(ValidateServerCertificate),
                null);
            try
            {
                await sslStream.AuthenticateAsClientAsync(targetHost: hostname, clientCertificates: certificatesCollection, enabledSslProtocols: SslProtocols.Tls12, checkCertificateRevocation: false);
                foreach (string dt in device_ids)
                {
                    MemoryStream memoryStream = new MemoryStream();
                    BinaryWriter writer = new BinaryWriter(memoryStream);
                    writer.Write((byte)0);
                    writer.Write((byte)0);
                    writer.Write((byte)32);

                    writer.Write(HexStringToByteArray(dt.ToUpper()));
                    //string payload = JsonConvert.SerializeObject(pn);
                    string payload = JsonConvert.SerializeObject(pn).Replace("content_available", "content-available");
                    writer.Write((byte)0);
                    writer.Write((byte)payload.Length);
                    byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
                    writer.Write(b1);
                    writer.Flush();
                    byte[] array = memoryStream.ToArray();
                    sslStream.Write(array);
                    sslStream.Flush();
                }

                client.Dispose();

                return Content("IOS Push Notification sent. Check your device.");
            }
            catch (AuthenticationException ex)
            {
                client.Dispose();
                return Content("IOS Push Notification FAILED authentication.");
            }
            catch (Exception e)
            {
                client.Dispose();
                return Content("IOS Push Notification FAILED");
            }
        }

    public class PushNotification_Ios
    {
        public PushNotification_APS aps { get; set; }
        //public string pushtype { get; set; } = "message";
    }

    public class PushNotification_APS
    {
        public Payload_IOS_Alert alert { get; set; }
        public int badge { get; set; } = 1;
        public string sound { get; set; } = "default";
        public int content_available { get; set; } = 0;
        public int notId { get; set; } = new System.Random().Next(0, 100000);
    }

    public class Payload_IOS_Alert
    {
        public string title { get; set; }
        public string body { get; set; }
    }
toddtsic commented 7 years ago

I asked pushtry.com the urls they are using for production vs dev and they write:

When Production checkbox is enabled it just changes the url to gateway.push.apple.com:2195

For development we use gateway.sandbox.push.apple.com:2195

I then changed my sever code to gateway.sandbox.push.apple.com:2195 from api.development.push.apple.com:2197

and iOS 9.3 then starts working but iOS 10.3 does not

That makes me think that the issue is going to be with 1) xcode configuration or 2) the plugin

In consideration of 1), xcode warnings in the console on running iOS10.3 are different, (will include below), the most glaring difference distinct to iOS10.3 is:

2017-04-25 07:37:20.987371-0700 TSICMobile[892:261247] libMobileGestalt MobileGestaltSupport.m:153: pid 892 (TSICMobile) does not have sandbox access for frZQaeyWLUvLjeuEK43hmg and IS NOT appropriately entitled 2017-04-25 07:37:20.987403-0700 TSICMobile[892:261247] libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID (see rdar://problem/11744455)

Has anyone gotton iOS 10.3 to work on xcode8.3? Could you share xcode settings?

XCode console output for iOS test:

2017-04-25 07:37:18.099360-0700 TSICMobile[892:261214] DiskCookieStorage changing policy from 2 to 0, cookie file: file:///private/var/mobile/Containers/Data/Application/39464CED-9BED-4F73-AB5F-70364A30ED43/Library/Cookies/Cookies.binarycookies
2017-04-25 07:37:18.148367-0700 TSICMobile[892:261214] Apache Cordova native platform version 4.3.1 is starting.
2017-04-25 07:37:18.149069-0700 TSICMobile[892:261214] Multi-tasking -> Device: YES, App: YES
2017-04-25 07:37:18.218916-0700 TSICMobile[892:261214] Using UIWebView
2017-04-25 07:37:18.220095-0700 TSICMobile[892:261214] [CDVTimer][handleopenurl] 0.070035ms
2017-04-25 07:37:18.222123-0700 TSICMobile[892:261214] [CDVTimer][intentandnavigationfilter] 1.968980ms
2017-04-25 07:37:18.222218-0700 TSICMobile[892:261214] [CDVTimer][gesturehandler] 0.051975ms
2017-04-25 07:37:18.239064-0700 TSICMobile[892:261214] [CDVTimer][file] 16.665995ms
2017-04-25 07:37:18.268074-0700 TSICMobile[892:261214] [CDVTimer][splashscreen] 28.949976ms
2017-04-25 07:37:18.276106-0700 TSICMobile[892:261214] [CDVTimer][statusbar] 7.955968ms
2017-04-25 07:37:18.277606-0700 TSICMobile[892:261214] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-04-25 07:37:18.278596-0700 TSICMobile[892:261214] [MC] Filtering mail sheet accounts for bundle ID: com.teamsportsinfo.api, source account management: 1
2017-04-25 07:37:18.280733-0700 TSICMobile[892:261214] [MC] Result: YES
2017-04-25 07:37:18.280849-0700 TSICMobile[892:261214] [MC] Filtering mail sheet accounts for bundle ID: com.teamsportsinfo.api, source account management: 1
2017-04-25 07:37:18.281424-0700 TSICMobile[892:261214] [MC] Result: YES
2017-04-25 07:37:18.293397-0700 TSICMobile[892:261214] [CDVTimer][socialsharing] 17.225027ms
2017-04-25 07:37:18.294645-0700 TSICMobile[892:261214] [CDVTimer][keyboard] 1.136959ms
2017-04-25 07:37:18.294728-0700 TSICMobile[892:261214] [CDVTimer][TotalPluginStartup] 74.707985ms
2017-04-25 07:37:18.303976-0700 TSICMobile[892:261214] createNotificationChecker
2017-04-25 07:37:18.304019-0700 TSICMobile[892:261214] not coldstart
2017-04-25 07:37:18.305423-0700 TSICMobile[892:261214] active
2017-04-25 07:37:18.305600-0700 TSICMobile[892:261214] PushPlugin skip clear badge
2017-04-25 07:37:18.423432-0700 TSICMobile[892:261214] [MC] Reading from public effective user settings.
2017-04-25 07:37:18.564355-0700 TSICMobile[892:261214] Resetting plugins due to page load.
2017-04-25 07:37:20.987371-0700 TSICMobile[892:261247] libMobileGestalt MobileGestaltSupport.m:153: pid 892 (TSICMobile) does not have sandbox access for frZQaeyWLUvLjeuEK43hmg and IS NOT appropriately entitled
2017-04-25 07:37:20.987403-0700 TSICMobile[892:261247] libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID (see <rdar://problem/11744455>)
2017-04-25 07:37:21.075891-0700 TSICMobile[892:261214] THREAD WARNING: ['File'] took '10.533691' ms. Plugin should use a background thread.
2017-04-25 07:37:21.103553-0700 TSICMobile[892:261214] Ionic Native: deviceready event fired after 2299 ms
2017-04-25 07:37:21.103612-0700 TSICMobile[892:261214] DEVICE READY FIRED AFTER 2208 ms
2017-04-25 07:37:21.103630-0700 TSICMobile[892:261214] OPEN database: __tsicmobiledb
2017-04-25 07:37:21.103960-0700 TSICMobile[892:261214] new transaction is waiting for open operation
2017-04-25 07:37:21.115429-0700 TSICMobile[892:261214] OPEN database: __tsicmobiledb - OK
2017-04-25 07:37:21.115480-0700 TSICMobile[892:261214] DB opened: __tsicmobiledb
2017-04-25 07:37:21.163731-0700 TSICMobile[892:261214] LoginPage: InitializeLoginPage
2017-04-25 07:37:21.452574-0700 TSICMobile[892:261214] Finished load of: file:///var/containers/Bundle/Application/E6BA92DF-716A-41C8-A443-9DD8CEFF9D48/TSICMobile.app/www/index.html
2017-04-25 07:37:21.542922-0700 TSICMobile[892:261214] eventorrolechanged trap in app.component
2017-04-25 07:37:22.705756-0700 TSICMobile[892:261214] ConfigurePush: Start
2017-04-25 07:37:22.705833-0700 TSICMobile[892:261214] isIOS:true
2017-04-25 07:37:22.705857-0700 TSICMobile[892:261214] isANDROID:false
2017-04-25 07:37:22.713948-0700 TSICMobile[892:261246] Push Plugin register called
2017-04-25 07:37:22.714010-0700 TSICMobile[892:261246] PushPlugin.register: setting badge to false
2017-04-25 07:37:22.714022-0700 TSICMobile[892:261246] PushPlugin.register: clear badge is set to 0
2017-04-25 07:37:22.714040-0700 TSICMobile[892:261246] PushPlugin.register: better button setup
2017-04-25 07:37:22.716745-0700 TSICMobile[892:261246] GCM Sender ID (null)
2017-04-25 07:37:22.716781-0700 TSICMobile[892:261246] Using APNS Notification
2017-04-25 07:37:22.725772-0700 TSICMobile[892:261214] Push Plugin register success: <f2b86bc8 24e55d4c fd02cab8 40d35d1e 9602d673 0f0c3d32 4a203ada e5ff28cd>
2017-04-25 07:37:22.743246-0700 TSICMobile[892:261214] f2b86bc824e55d4cfd02cab840d35d1e9602d6730f0c3d324a203adae5ff28cd
2017-04-25 07:37:22.743300-0700 TSICMobile[892:261214] DEBUG Device LATESTDEVICEID: 291EA5D3-4152-4D14-836A-3DF1CD4283CB
2017-04-25 07:37:22.743321-0700 TSICMobile[892:261214] DEBUG Device DEVICEID: 291EA5D3-4152-4D14-836A-3DF1CD4283CB
2017-04-25 07:37:22.743339-0700 TSICMobile[892:261214] DEBUG device TOKEN: f2b86bc824e55d4cfd02cab840d35d1e9602d6730f0c3d324a203adae5ff28cd
2017-04-25 07:37:22.743357-0700 TSICMobile[892:261214] DEBUG device TYPE: ios
macdonst commented 7 years ago

@toddtsic if you open the project in Xcode can you check to see if under the capabilities that push notification is turned on? This is required for iOS 10.

toddtsic commented 7 years ago

Simon,

Thanks for responding.

Yes: my Capabilities include: Push Notifications: On, Add the Push Notifications feature to your App ID, Add the Push Notifications entitlement to your entitlements file

xcode 8.3.2 console shows:

2017-04-25 08:25:20.035419-0700 TSICMobile[253:8305] libMobileGestalt MobileGestaltSupport.m:153: pid 253 (TSICMobile) does not have sandbox access for frZQaeyWLUvLjeuEK43hmg and IS NOT appropriately entitled 2017-04-25 08:25:20.035456-0700 TSICMobile[253:8305] libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID (see rdar://problem/11744455)

Have been researching, haven't found anything useful other than "Apple Scripts error, nothing you can do about it..."

Greatly appreciate any thoughts you may have.

Todd

On Tue, Apr 25, 2017 at 8:08 AM, Simon MacDonald notifications@github.com wrote:

@toddtsic https://github.com/toddtsic if you open the project in Xcode can you check to see if under the capabilities that push notification is turned on? This is required for iOS 10.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/phonegap/phonegap-plugin-push/issues/1691#issuecomment-297061005, or mute the thread https://github.com/notifications/unsubscribe-auth/AJeir2jzKW3ez9fqybch0Q-F5DF7jh2Bks5rzgxmgaJpZM4NGx-q .

-- Todd Greenwald President, TeamSportsInfo.com tgreenwald@teamsportsinfo.com 410-703-3450

toddtsic commented 7 years ago

OMG got it, almost...!

I applied:

http://stackoverflow.com/questions/37806538/code-signing-is-required-for-product-type-application-in-sdk-ios-10-0-stic#answer-39498874

With that I got iOS 10.3 to receive one push notification, nothing after...

Anyone else out there using Ionic and iOS 10+ with any advice?

Todd

gcoria commented 7 years ago

Got the same problem i'm using the plugin with firebase and the device registers but doesn't receive notifications, i have the same enviroment that you and nothing seems to work

skielo commented 7 years ago

Hey guys I have the same issue. Also using firebase plugin, the device registers but the notification doesn't come. Any advice?

gcoria commented 7 years ago

I change the library to cordova-fcm and now works fine, i don't know what was the problem with ios with these library in android was working without any problem, i'm sure i was doing something wrong :disappointed:

lock[bot] commented 6 years ago

This thread has been automatically locked.