coronalabs / corona

Solar2D Game Engine main repository (ex Corona SDK)
https://solar2d.com/
MIT License
2.53k stars 273 forks source link

[Android 12]: Local Notification v2 plugin is not working on Android 12 #441

Closed ChaseTargaryen closed 2 years ago

ChaseTargaryen commented 2 years ago

Describe the bug Like the title said, the plugin itself isn't working at all on Android 12. Even the sample code on documentation is not working.

To Reproduce Steps to reproduce the behavior:

  1. Require the notification plugin
  2. Try the sample code from documetation
  3. Build and see.

Target platform and where build was made:

Something weird happened after I switch to v2. I was using the plugin the same way as I used v1. I got these warnings:

Corona  : WARNING: notifications.scheduleNotification(time [, options]), Invalid option 'custom'
 Corona  : WARNING: notifications.scheduleNotification(time [, options]), Invalid option 'alert'
Corona  : WARNING: notifications.scheduleNotification(time [, options]), Invalid option 'sound'

whole test project or build.settings

settings =
{
  build =
  {
    neverStripDebugInfo = true
  },

  plugins =
  {

    ["plugin.universalLinks"] = {publisherId="tech.scotth"},
    ["plugin.reviewPopUp"] = {publisherId="tech.scotth"},

    ["plugin.androidPreview"] = {publisherId="tech.scotth"},        
    ["CoronaProvider.native.popup.quickLook"] = { publisherId = "com.coronalabs" },

    ["plugin.adjust"] = { publisherId = "com.adjust" },

    ["plugin.pagecurl"] = { publisherId = "com.xibalbastudios" },
    ["plugin.iCloud"]               = { publisherId = "com.coronalabs",supportedPlatforms = { iphone=true, osx=true, appletvos=true }},
    ["plugin.notifications.v2"]        = { publisherId = "com.coronalabs" },

    ["plugin.apple.iap"]            = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true } },
    ["plugin.google.iap.billing"] = { publisherId = "com.coronalabs" },

    ["plugin.amazon.iap"]           = { publisherId = "com.coronalabs", supportedPlatforms={ ["android-kindle"]=true} },
    ["plugin.CoronaSplashControl"]  = { publisherId = "com.coronalabs" },
    ["plugin.zip"]                  = { publisherId = "com.coronalabs" },
    ["CoronaProvider.native.popup.activity"] = {publisherId = "com.coronalabs", supportedPlatforms = { iphone=true } },
    ["CoronaProvider.native.popup.social"] = { publisherId = "com.coronalabs" },
    ["plugin.pasteboard"] = { publisherId = "com.coronalabs" },
    ["plugin.utf8"] = { publisherId = "com.coronalabs"},
    ["plugin.orientation"] = {publisherId = "com.studycat.orientation"},
  },

  splashScreen = { enable = false },

  orientation ={
      default = "landscapeRight",
      supported = {"portrait", "landscapeLeft", "landscapeRight"}, 
  },  

  iphone =
  {
    xcassets = "Images.xcassets",
    entitlements = {

    },
    plist = 
    { 
          -- NSUserTrackingUsageDescription = "This would allow the app to advertise better.",
          ITSAppUsesNonExemptEncryption = false,
          NSMicrophoneUsageDescription = 'This app features voice recording games.',
          -- NSPhotoLibraryUsageDescription = "This app would like to access the photo library.",
          -- NSPhotoLibraryAddUsageDescription = "This app would like to add the photo library.",
          NSCameraUsageDescription = "Used to scan QR codes and barcodes.",
          NSAppTransportSecurity = 
          {
            UIStatusBarHidden = true, 
            UIPrerenderedIcon = true,
            CFBundleDisplayName = "SCAMP",
            CFBundleVersion = "1", -- use date
            CFBundleShortVersionString = "1.0",

            UILaunchStoryboardName = "LaunchScreen",

            CFBundleLocalizations = 
            {
                "en",
                "gb",
                "fr",
                "de",
                "it",
                "es",
                "pt",
                "ja",
                "zh-Hans",
                "zh-Hant",

                --"ar",
                "da",
                "nl",
                "fi",
                "ko",
                "nb",
                "ru",
                "sv",
                "tr",
                "vi",
            },
    }
  },

  android =
  {
    minSdkVersion = "21",
    applicationChildElements =
      {
        [[
          <receiver android:name="com.adjust.sdk.AdjustReferrerReceiver" android:exported="true" >
              <intent-filter>
                  <action android:name="com.android.vending.INSTALL_REFERRER" />
              </intent-filter>
          </receiver>
        ]]
      },

    strings = 
        {
        },
     },
      largeHeap = true,           -- only takes effect on android 3.0 and above.
      usesExpansionFile = false, 
      usesPermissions = {
         "com.android.vending.BILLING",
         "android.permission.INTERNET",
         "com.android.vending.CHECK_LICENSE",
         "android.permission.WRITE_EXTERNAL_STORAGE",
         "android.permission.RECORD_AUDIO",
         "android.permission.CAMERA",
         "android.permission.ACCESS_NETWORK_STATE"
      },
  },

  window = 
  {

  },

  osx = {
      entitlements = {
          ["com.apple.security.assets.pictures.read-write"] = true,
      },
  },

  macos ={
    entitlements = {
      ["com.apple.security.network.client"] = true,
    },
    plist = 
    {   
          NSAppTransportSecurity =
             {
                NSAllowsArbitraryLoads = true,
                NSExceptionDomains =
                {
                   -- for webViewSocket on ios 9
                   ["localhost"] = { NSExceptionAllowsInsecureHTTPLoads = true, NSIncludesSubdomains = true, NSThirdPartyExceptionAllowsInsecureHTTPLoads = true },

                },
             },
    }
  }
}
ChaseTargaryen commented 2 years ago

I tried the plugin with a clean project. No luck on Android 12.

build.setting.


settings =
{
    orientation =
    {
        -- Supported values for orientation:
        -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight
        default = "portrait",
        supported = { "portrait", },
    },

    --
    -- Android section
    --
    android =
    {
        usesPermissions =
        {
            "android.permission.INTERNET",
            "android.permission.RECEIVE_BOOT_COMPLETED",
            "android.permission.POST_NOTIFICATIONS"
        },
    },

    --
    -- iOS section
    --
    iphone =
    {
        xcassets = "Images.xcassets",
        plist =
        {
            UIStatusBarHidden = false,
            UILaunchStoryboardName = "LaunchScreen",
        },
    },

    --
    -- Plugins section
    --
    plugins =
    {
        ["plugin.notifications.v2"] =
        {
            publisherId = "com.coronalabs"
        },
    },

    --
    -- Project section
    --
    excludeFiles =
    {
        -- Exclude unnecessary files for each platform
        all = { "Icon.png", "Icon-*dpi.png", "Images.xcassets", },
        android = { "LaunchScreen.storyboardc", },
    },
}
  1. My testing code:

local notifications = require( "plugin.notifications.v2" )

-- Get the app's launch arguments in case it was started when the user tapped on a notification local launchArgs = ...

-- Set up notification options local options = { alert = "Start a free trial!\ Try all of the units in the app for 7 days.", badge = 0, sound = "alarm.caf", custom = { date="Sep 03 00:00", hoursSinceInstall="744", message="LN_START_FREE_TRIAL", name="LN_START_FREE_TRIAL", order="9", orientation="portrait", postcard="notification-start-trial", userType="free" }, }

local options2 = { alert = "Start a free trial! Try all of the units in the app for 7 days.", badge = 0, sound = "alarm.caf", custom = { name = "bar" } }

-- Schedule a notification to occur 60 seconds from now local notification1 = notifications.scheduleNotification( 10, options )

local notification2 = notifications.scheduleNotification( 20, options2 ) -- Listen for notifications local function onNotification( event ) print(event.name) print(event.custom.name) end Runtime:addEventListener( "notification", onNotification )

-- The launch arguments provide a notification event if this app was started when the user tapped on a notification -- In this case, you must call the notification listener manually if ( launchArgs and launchArgs.notification ) then onNotification( launchArgs.notification ) end

scottrules44 commented 2 years ago

This is fixed with 2022.3681+