1

Good morning,

I am having issues in my iOS APP when trying to register for remote notifications using the SFMC Swift SDK:

sfmc-sdk-ios v1.1.0 MarketingCloudSDK-iOS v8.1.0

The steps I am following are:

  1. Initialize the SDK

     func configureSdk() -> Bool {
    
     // To Override the Keychain Error to be considered fatal or not (Default value is true)
     SFMCSdk.setKeychainAccessErrorsAreFatal(errorsAreFatal: false)
    
     let mobilePushConfiguration = PushConfigBuilder(appId: Configuration.shared.data.sfmcAppId)
         .setAccessToken(Configuration.shared.data.sfmcAccessToken)
         .setMarketingCloudServerUrl(URL(string: Configuration.shared.data.sfmcAppEndpoint)!)
         .setMid(Configuration.shared.data.sfmcMid)
         .setInboxEnabled(false)
         .setLocationEnabled(false)
         .setAnalyticsEnabled(true)
         .build()
    
     let completionHandler: (OperationResult) -> Void = { result in
         if result == .success {
             self.setupMobilePush()
         }
     }
    
     SFMCSdk.initializeSdk(ConfigBuilder().setPush(config: mobilePushConfiguration, onCompletion: completionHandler).build())
    
     return true
    

    }

  2. Request authorization, which is called in the completionHandler of the SDK registration.

  3. Register for remote notifications, called when the authorization has been granted:

     func setupMobilePush() {
     SFMCSdk.mp.setURLHandlingDelegate(self)
    
     DispatchQueue.main.async {
         UNUserNotificationCenter.current().delegate = self
    
         UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: {(_ granted: Bool, _ error: Error?) -> Void in
             if error == nil {
                 Configuration.shared.data.sfmcNotificationPermissionGranted = granted
    
                 if granted && !SFMCSdk.mp.pushEnabled() {
                     SFMCSdk.mp.setPushEnabled(true)
                 } else if !granted && SFMCSdk.mp.pushEnabled() {
                     SFMCSdk.mp.setPushEnabled(false)
                 }
    
                 self.taskPutPushEnabled = Task { @MainActor [weak self] in
                     do {
                         try await self?.notificationUseCase.putPushEnabled()
                         DSPManager.shared.setIsPushEnabledSentOK(true)
                     } catch {
                         DSPManager.shared.setIsPushEnabledSentOK(false)
                     }
                     self?.taskPutPushEnabled = nil
                 }
    
                 DispatchQueue.main.async {
                     print("*** ALLOW NOTIFICATIONS: \(granted)")
                     UIApplication.shared.registerForRemoteNotifications()
                 }
             }
         })
     }
    

    }

However, I am not receiving the mobile push notifications. When trying to find my device in the Dashboard, I can see that I am not Opted In, and the Opt Out Method is "Missing or invalid Device Token".

Missing or invalid Device Token

I have no clue where the problem may be, I think the setup is correct. Anyone has faced the same issue?

1 Answer 1

0

Please check the environment in which the app is built (ie) either production or sandbox environment and point the same in the MC UI.

You can check the environment using the script in send a test push from https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/trouble/ios-debugging.html (note: "endpoint" in the script is pointed to apple's sandbox environment. Please point to production api.push.apple.com server to test on prod environment.)

Thanks, Prakashini

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .