Skip to content

Commit

Permalink
Apple platform fixes
Browse files Browse the repository at this point in the history
* Fix issue with passing the device token
* Update PubNub Swift SDK dependency
  • Loading branch information
jguz-pubnub committed Mar 6, 2025
1 parent c30e2f0 commit b2895b5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 55 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dokka = "1.9.20"
kotlinx_datetime = "0.6.1"
kotlinx_coroutines = "1.9.0"
pubnub_js = "8.6.0"
pubnub_swift = "8.3.0"
pubnub_swift = "9.0.0"

[libraries]
retrofit2 = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit2" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.pubnub.api.endpoints.push

import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.addChannelsToPushNotificationsWithChannels
import com.pubnub.api.PubNubException
import com.pubnub.api.enums.PNPushEnvironment
import com.pubnub.api.enums.PNPushType
import com.pubnub.api.models.consumer.push.PNPushAddChannelResult
Expand All @@ -11,9 +10,7 @@ import com.pubnub.api.v2.callbacks.Result
import com.pubnub.kmp.PNFuture
import com.pubnub.kmp.onFailureHandler
import com.pubnub.kmp.onSuccessHandler
import com.pubnub.kmp.toNSData
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.NSData

/**
* @see [PubNub.addPushNotificationsOnChannels]
Expand All @@ -30,16 +27,14 @@ class AddChannelsToPushImpl(
private val environment: PNPushEnvironment
) : AddChannelsToPush {
override fun async(callback: Consumer<Result<PNPushAddChannelResult>>) {
deviceId.toNSData()?.let { data: NSData ->
pubnub.addChannelsToPushNotificationsWithChannels(
channels = channels,
deviceId = data,
pushType = pushType.toParamString(),
topic = topic.orEmpty(),
environment = environment.toParamString(),
onSuccess = callback.onSuccessHandler { PNPushAddChannelResult() },
onFailure = callback.onFailureHandler()
)
} ?: callback.accept(Result.failure(PubNubException("Cannot create NSData from $deviceId")))
pubnub.addChannelsToPushNotificationsWithChannels(
channels = channels,
deviceId = deviceId,
pushType = pushType.toParamString(),
topic = topic.orEmpty(),
environment = environment.toParamString(),
onSuccess = callback.onSuccessHandler { PNPushAddChannelResult() },
onFailure = callback.onFailureHandler()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.pubnub.api.endpoints.push

import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.listPushChannelsWithDeviceId
import com.pubnub.api.PubNubException
import com.pubnub.api.enums.PNPushEnvironment
import com.pubnub.api.enums.PNPushType
import com.pubnub.api.models.consumer.push.PNPushListProvisionsResult
Expand All @@ -11,9 +10,7 @@ import com.pubnub.api.v2.callbacks.Result
import com.pubnub.kmp.PNFuture
import com.pubnub.kmp.onFailureHandler
import com.pubnub.kmp.onSuccessHandler
import com.pubnub.kmp.toNSData
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.NSData

/**
* @see [PubNub.auditPushChannelProvisions]
Expand All @@ -29,15 +26,17 @@ class ListPushProvisionsImpl(
private val environment: PNPushEnvironment
) : ListPushProvisions {
override fun async(callback: Consumer<Result<PNPushListProvisionsResult>>) {
deviceId.toNSData()?.let { data: NSData ->
pubnub.listPushChannelsWithDeviceId(
deviceId = data,
pushType = pushType.toParamString(),
topic = topic.orEmpty(),
environment = environment.toParamString(),
onSuccess = callback.onSuccessHandler { PNPushListProvisionsResult(channels = it?.filterIsInstance<String>() ?: emptyList()) },
onFailure = callback.onFailureHandler()
)
} ?: callback.accept(Result.failure(PubNubException("Cannot create NSData from $deviceId")))
pubnub.listPushChannelsWithDeviceId(
deviceId = deviceId,
pushType = pushType.toParamString(),
topic = topic.orEmpty(),
environment = environment.toParamString(),
onSuccess = callback.onSuccessHandler {
PNPushListProvisionsResult(
channels = it?.filterIsInstance<String>() ?: emptyList()
)
},
onFailure = callback.onFailureHandler()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.pubnub.api.endpoints.push

import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.removeAllChannelsFromPushWithPushType
import com.pubnub.api.PubNubException
import com.pubnub.api.enums.PNPushEnvironment
import com.pubnub.api.enums.PNPushType
import com.pubnub.api.models.consumer.push.PNPushRemoveAllChannelsResult
Expand All @@ -11,9 +10,7 @@ import com.pubnub.api.v2.callbacks.Result
import com.pubnub.kmp.PNFuture
import com.pubnub.kmp.onFailureHandler
import com.pubnub.kmp.onSuccessReturnValue
import com.pubnub.kmp.toNSData
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.NSData

/**
* @see [PubNub.removeAllPushNotificationsFromDeviceWithPushToken]
Expand All @@ -29,15 +26,13 @@ class RemoveAllPushChannelsForDeviceImpl(
private val environment: PNPushEnvironment
) : RemoveAllPushChannelsForDevice {
override fun async(callback: Consumer<Result<PNPushRemoveAllChannelsResult>>) {
deviceId.toNSData()?.let { data: NSData ->
pubnub.removeAllChannelsFromPushWithPushType(
pushType = pushType.toParamString(),
deviceId = data,
topic = topic.orEmpty(),
environment = environment.toParamString(),
onSuccess = callback.onSuccessReturnValue(PNPushRemoveAllChannelsResult()),
onFailure = callback.onFailureHandler()
)
} ?: callback.accept(Result.failure(PubNubException("Cannot create NSData from $deviceId")))
pubnub.removeAllChannelsFromPushWithPushType(
pushType = pushType.toParamString(),
deviceId = deviceId,
topic = topic.orEmpty(),
environment = environment.toParamString(),
onSuccess = callback.onSuccessReturnValue(PNPushRemoveAllChannelsResult()),
onFailure = callback.onFailureHandler()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.pubnub.api.endpoints.push

import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.removeChannelsFromPushWithChannels
import com.pubnub.api.PubNubException
import com.pubnub.api.enums.PNPushEnvironment
import com.pubnub.api.enums.PNPushType
import com.pubnub.api.models.consumer.push.PNPushRemoveChannelResult
Expand All @@ -11,9 +10,7 @@ import com.pubnub.api.v2.callbacks.Result
import com.pubnub.kmp.PNFuture
import com.pubnub.kmp.onFailureHandler
import com.pubnub.kmp.onSuccessHandler
import com.pubnub.kmp.toNSData
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.NSData

/**
* @see [PubNub.removePushNotificationsFromChannels]
Expand All @@ -30,16 +27,14 @@ class RemoveChannelsFromPushImpl(
private val environment: PNPushEnvironment,
) : RemoveChannelsFromPush {
override fun async(callback: Consumer<Result<PNPushRemoveChannelResult>>) {
deviceId.toNSData()?.let { data: NSData ->
pubnub.removeChannelsFromPushWithChannels(
channels = channels,
deviceId = data,
pushType = pushType.toParamString(),
topic = topic.orEmpty(),
environment = environment.toParamString(),
onSuccess = callback.onSuccessHandler { PNPushRemoveChannelResult() },
onFailure = callback.onFailureHandler()
)
} ?: callback.accept(Result.failure(PubNubException("Cannot create NSData from $deviceId")))
pubnub.removeChannelsFromPushWithChannels(
channels = channels,
deviceId = deviceId,
pushType = pushType.toParamString(),
topic = topic.orEmpty(),
environment = environment.toParamString(),
onSuccess = callback.onSuccessHandler { PNPushRemoveChannelResult() },
onFailure = callback.onFailureHandler()
)
}
}

0 comments on commit b2895b5

Please sign in to comment.