Pushwoosh / pushwoosh-appcelerator-titanium

Other
33 stars 16 forks source link

Badge not increasing #93

Closed macasfaj closed 11 months ago

macasfaj commented 12 months ago

Hi! We have a problem with the badge of the App. From the server, as explained in the documentation, we are sending a +1. But the badge never increases. If I receive several pushes, it always stays at 1.

Titanium CLI v6.1.1, SDK v12.2.0.GA

The push in server is like this:

image

But the badge is always 1 in iOS.

Could you help me, please? Thanks.

wfhm commented 12 months ago

@macasfaj Could you please send us the link to the docs you were using for badge integration?

Starting with the 6.4.0 release of our native iOS SDK, badges are handled by a Notification Service Extension. This means that you have to add some ObjC/Swift code to your native iOS project.

The problem is that in Titanium, you do not have direct access to the Xcode project. However, you can work around it like described here:

https://stackoverflow.com/questions/35230242/how-do-i-run-the-xcode-project-generated-by-titanium/35261140#35261140

After you get access to the native project, you can just follow this guide to add Notification Service Extension and set up badges:

https://docs.pushwoosh.com/platform-docs/pushwoosh-sdk/ios-push-notifications/setting-up-badges

wfhm commented 11 months ago

@macasfaj

I've came up with a bit easier solution to create an extension. You can find the example project in attachments.

As a prerequisite, you should have a separate ID and provisioning profile for your extension. Its bundle ID should start with your app's bundle ID, i.e. for com.pushwoosh.newdemo App bundle ID I have com.pushwoosh.newdemo.NotificationServiceExtension. Add push notifications and app groups capabilities to this ID.

  1. First, you should create an extension to use in your project. For simplicity, just copy and paste the contents of the extensions directory from the attached archive to your project (create the extensions folder if there is none in your root)
  2. Open the .xcodeproj in the extension and go to Signing and Capabilities tab. Set bundle identifier to ${YOUR_BUNDLE_ID}.NotificationServiceExtension.
  3. In App groups tab create a new app group that you will use in your project
  4. In extension's info.plist replace the value of PW_APP_GROUPS_NAME key with the name of your new app group
  5. Now, in register your extension in your tiapp.xml:
    <ios>
        ...
        <extensions>
          <extension projectPath="extensions/NotificationServiceExtension/com.appcelerator.sample.richpush.xcodeproj">
              <target name="notificationservice">
                  <provisioning-profiles>
                      <device>d0481fc8-6d1e-489b-aa8c-8bdefc7f8b10</device>
                      <dist-appstore/>
                      <dist-adhoc/>
                  </provisioning-profiles>
              </target>
            </extension>
        </extensions>
        ...
     </ios>

    Set UUIDs of your extension provisioning profiles in the element. You can get these IDs by running ti info:

Screenshot 2023-10-25 at 21 55 03
  1. In your tiapp.xml add the PW_APP_GROUPS_NAME key with the name of your group to // element:
                <key>PW_APP_GROUPS_NAME</key>
                <string>group.com.pushwoosh.newdemo_group</string>

    com.pushwoosh.newdemo.zip

  2. Copy the notificationservice.entitlements from the example project to your project's root and replace app group name with yours:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>aps-environment</key>
    <string>development</string>
    <key>com.apple.security.application-groups</key>
    <array>
        <string>group.com.pushwoosh.newdemo_group</string>
    </array>
    </dict>
    </plist>
  3. Finally, copy your Xcode project's entitlements from build/iphone/ directory to Titanium project root and add the app group key to it:
        <key>com.apple.security.application-groups</key>
    <array>
        <string>group.com.pushwoosh.newdemo_group</string>
    </array>

That's it, the badges should start incrementing correctly now. Please let me know about the results!

macasfaj commented 11 months ago

Thanks! I'll check! :)