Skip to content

Commit

Permalink
Merge pull request #1 from cometchat-pro/v3
Browse files Browse the repository at this point in the history
v3.0.1
  • Loading branch information
pushpsenairekar2911 authored Aug 18, 2021
2 parents 901b07e + 9985603 commit bb76e76
Show file tree
Hide file tree
Showing 537 changed files with 23,890 additions and 8,953 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified APNS + Callkit/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions APNS + Callkit/NotificationServiceExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSCameraUsageDescription</key>
<string>Access Camera</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
</dict>
<key>NSCameraUsageDescription</key>
<string>Access Camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>Access Microphone</string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<key>aps-environment</key>
<string>development</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.cometchat.apns</string>
</array>
<array/>
</dict>
</plist>
6 changes: 4 additions & 2 deletions APNS + Callkit/Podfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@


target 'PushNotificationSample-APNS' do
pod 'CometChatPro','2.2.1'
pod 'CometChatPro','3.0.1'
pod 'CometChatCalls','2.1.0'
end

target 'NotificationServiceExtension' do
pod 'CometChatPro','2.2.1'
pod 'CometChatPro','3.0.1'
pod 'CometChatCalls','2.1.0'
end
5,931 changes: 3,698 additions & 2,233 deletions APNS + Callkit/PushNotificationSample-APNS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "EC1CAD8E-6EEE-4E67-8BFC-F583CA4F7C6C"
type = "1"
version = "2.0">
</Bucket>
Binary file modified APNS + Callkit/iOS-PushNotification/.DS_Store
Binary file not shown.
134 changes: 99 additions & 35 deletions APNS + Callkit/iOS-PushNotification/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import CometChatPro
import UserNotifications
import PushKit
import CallKit
import AudioToolbox
import AVKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand Down Expand Up @@ -91,11 +93,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// [START receive_message]
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { }

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

completionHandler(UIBackgroundFetchResult.newData)
}
// func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
// fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
//
// completionHandler(UIBackgroundFetchResult.newData)
// }

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print( "Unable to register for remote notifications: \(error.localizedDescription)")
Expand Down Expand Up @@ -192,13 +194,49 @@ extension AppDelegate : UNUserNotificationCenterDelegate {


func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {

if let userInfo = response.notification.request.content.userInfo as? [String : Any], let messageObject = userInfo["message"] as? [String:Any] {
print("didReceive: \(userInfo)")
if let baseMessage = CometChat.processMessage(messageObject).0 {
switch baseMessage.messageCategory {
case .message:
print("Message Object Received: \(String(describing: (baseMessage as? TextMessage)?.stringValue()))")

switch baseMessage.receiverType {
case .user:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if let user = baseMessage.sender {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "didReceivedMessageFromUser"), object: nil, userInfo: ["user":user])
}
}
case .group:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if let group = baseMessage.receiver as? Group {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "didReceivedMessageFromGroup"), object: nil, userInfo: ["group":group])
}
}
@unknown default: break
}

case .action: break
case .call: break
case .custom: break
@unknown default: break
}
}
}
completionHandler()
}

func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceivent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("willPresent notification: \(notification.request.content.userInfo)")


if let userInfo = notification.request.content.userInfo as? [String : Any], let messageObject =
userInfo["message"], let str = messageObject as? String, let dict = str.stringTodictionary() {
userInfo["message"], let dict = messageObject as? [String : Any] {

if let baseMessage = CometChat.processMessage(dict).0 {
switch baseMessage.messageCategory {
Expand Down Expand Up @@ -292,7 +330,11 @@ extension AppDelegate: PKPushRegistryDelegate , CXProviderDelegate {
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: name)
update.hasVideo = false
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in
if error == nil {
self.configureAudioSession()
}
})
}

case .audio where call.receiverType == .group:
Expand All @@ -308,7 +350,11 @@ extension AppDelegate: PKPushRegistryDelegate , CXProviderDelegate {
update.remoteHandle = CXHandle(type: .generic, value: group)
update.hasVideo = false

provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in
if error == nil {
self.configureAudioSession()
}
})
}

case .video where call.receiverType == .user:
Expand All @@ -323,7 +369,11 @@ extension AppDelegate: PKPushRegistryDelegate , CXProviderDelegate {
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: name)
update.hasVideo = true
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in
if error == nil {
self.configureAudioSession()
}
})


}
Expand All @@ -339,7 +389,11 @@ extension AppDelegate: PKPushRegistryDelegate , CXProviderDelegate {
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: group)
update.hasVideo = true
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in
if error == nil {
self.configureAudioSession()
}
})
}
case .audio: break
case .video: break
Expand All @@ -361,6 +415,16 @@ extension AppDelegate: PKPushRegistryDelegate , CXProviderDelegate {
}
}

func configureAudioSession() {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, options: [.mixWithOthers, .allowBluetooth, .defaultToSpeaker])
try AVAudioSession.sharedInstance().setActive(true)

} catch let error as NSError {
print(error)
}
}

func providerDidReset(_ provider: CXProvider) {

}
Expand All @@ -382,26 +446,26 @@ extension AppDelegate: PKPushRegistryDelegate , CXProviderDelegate {
// -------------------------------------------------------------------------------------------------------------//


extension String {
func stringTodictionary() -> [String:Any]? {
var dictonary:[String:Any]?
if let data = self.data(using: .utf8) {
do {
dictonary = try JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]
if let myDictionary = dictonary
{
return myDictionary;
}
} catch let error as NSError {
print(error)
}
}
return dictonary;
}
}
//extension String {
//
// func stringTodictionary() -> [String:Any]? {
//
// var dictonary:[String:Any]?
//
// if let data = self.data(using: .utf8) {
//
// do {
// dictonary = try JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]
//
// if let myDictionary = dictonary
// {
// return myDictionary;
// }
// } catch let error as NSError {
// print(error)
// }
//
// }
// return dictonary;
// }
//}
Binary file modified APNS + Callkit/iOS-PushNotification/Library/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit bb76e76

Please sign in to comment.