iOS Question b4i not playing like WhatsAPP

IamTrying

Active Member
Licensed User
When from the server my app receive Push notification it only show notification but do not bring the UI in front.
Each push notification is incoming call like "ANSWER call or REJECT call" how do i trigger my app UI instead of showing a notification only?
Do i have to send UI interface from the Push server?

Where now its sending notification? Please advise (i am now lost, i want to make ringing UI like whatsAPP answer call or reject call)

B4X:
Private Sub Application_Start (Nav As NavigationController)
    NativeMe  = Me
    NavControl = Nav
   
    App.RegisterUserNotifications(True, True, True)
    App.RegisterForRemoteNotifications
End Sub

Private Sub Application_PushToken (Success As Boolean, Token() As Byte)
    If Success Then   
        Log(">>> Token submit")
        Dim bc As ByteConverter
        myToken = bc.HexFromBytes(Token)               
    Else
        Log("Error getting token: " & LastException)
    End If
End Sub

Sub submitToken()
    Log(">>> submitToken")
    ' Token upload
    Dim j As HttpJob
    j.Initialize("j", Me)
    j.PostString(ServerUrl & "/devicetoken", _
                        "token=" & myToken & _
                        "&type=1&userid=" & myUserID & "&username=" & myUsername)
End Sub


Private Sub Application_RemoteNotification (Message As Map)
    'Log("Remote notification: " & Message)
    Dim m As Map = Message.Get("aps")
    Log(m.Get("userid"))
    Log(m.Get("username"))
   
    Dim mm As Map = m.Get("alert")
    Log(mm.Get("body")) 
   
   
End Sub
 

IamTrying

Active Member
Licensed User
Where do i mention in b4i code what pkpushtype ( Reference 2: https://developer.apple.com/documentation/pushkit/pkpushtype/1614481-voip ) to use?

- Reference 1: https://websitebeaver.com/callkit-swift-tutorial-super-easy#receive-call-when-app-is-closed

Project: https://github.com/WebsiteBeaver/callkit-tutorial/tree/master/receive-call-when-app-is-closed

B4X:
import UIKit
import CallKit
import PushKit

class ViewController: UIViewController, CXProviderDelegate, PKPushRegistryDelegate {

   override func viewDidLoad() {
       let registry = PKPushRegistry(queue: nil)
       registry.delegate = self
       registry.desiredPushTypes = [PKPushType.voIP]
   }

   func providerDidReset(_ provider: CXProvider) {
   }

   func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
       action.fulfill()
   }

   func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
       action.fulfill()
   }

   func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
       print(pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined())
   }

   func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
       let config = CXProviderConfiguration(localizedName: "My App")
       config.iconTemplateImageData = UIImagePNGRepresentation(UIImage(named: "pizza")!)
       config.ringtoneSound = "ringtone.caf"
       config.includesCallsInRecents = false;
       config.supportsVideo = true;
       let provider = CXProvider(configuration: config)
       provider.setDelegate(self, queue: nil)
       let update = CXCallUpdate()
       update.remoteHandle = CXHandle(type: .generic, value: "Pete Za")
       update.hasVideo = true
       provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
   }

}
 
Last edited:
Upvote 0

IamTrying

Active Member
Licensed User
Thank you. We need that PushKit library in B4i (Objective-C is a nightmare it just kill all time, if its C++11/Qt5 or Swift it was doable alone).
blogCoverNew.jpg

Screen_Shot_2017-12-29_at_15.56.36.png
 
Last edited:
Upvote 0
Top