Code Monkey home page Code Monkey logo

ctnotificationservice's Introduction

CTNotificationService

Version codebeat badge SwiftPM compatible Carthage compatible License Platform iOS 10.0+

👋 Introduction

A simple Notification Service Extension class to add media attachments to iOS 10 rich push notifications. Starting with iOS 10 you can add media attachments (image, gif, video, audio) to iOS push notifications. This library provides a simple drop-in class to accomplish that.

Rich push notifications are enabled in iOS 10 via a Notification Service Extension, a separate and distinct binary embedded in your app bundle.

📋 Requirements

  1. Compatible with iOS version 10.0 or above

  2. Configure your app for Push and add a Notification Service Extension target

    • Enable push notifications in your main app.

    • Create a Notification Service Extension in your project. To do that in your Xcode project, select File -> New -> Target and choose the Notification Service Extension template.

notification service extension

🎉 Installation

CocoaPods

Install CTNotificationService in your Notification Service Extension via CocoaPods

Your Podfile should look something like this:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'

use_frameworks!

target 'YOUR_NOTIFICATION_SERVICE_TARGET_NAME' do  
    pod 'CTNotificationService'  
end     

Then run pod install.

See example Podfile here.

Carthage

CTNotificationService supports Carthage to package your dependencies as a framework.

To integrate CTNotificationService into your Xcode project using Carthage, specify the following in your Cartfile:

github "CleverTap/CTNotificationService"

Run carthage update to build the framework and drag the built CTNotificationService.framework into your Xcode project.

Swift Package Manager

Swift Package Manager is an Xcode tool that installs project dependencies. To use it to install CTNotificationService SDK, follow these steps:

  • In Xcode, navigate to File -> Swift Package Manager -> Add Package Dependency.
  • Enter https://github.com/CleverTap/CTNotificationService.git when choosing package repo and Click Next.
  • On the next screen, Select an SDK version (by default, Xcode selects the latest stable version). Click Next.
  • Click Finish and ensure that the CTNotificationService has been added to the appropriate target.

🚀 Integration

Configure your Notification Service Extension to use the CTNotificationServiceExtension class

By default CTNotificatonServiceExtension will look for the push payload key ct_mediaUrl with a value representing the url to your media file and the key ct_mediaType with a value of the type of media (image, video, audio or gif).

If you are happy with the default key names, you can simply insert CTNotificationServiceExtension in place of your extension class name as the value for the NSExtension -> NSExtensionPrincipalClass entry in your Notfication Service Extension target Info.plist. See example here.

Alternatively, you can leave the NSExtensionPrincipalClass entry unchanged and instead have your NotificationService class extend the CTNotificationServiceExtension class. You can then also override the defaults to your chosen key names if you wish. See Swift example here and Objective-C example here. In that case, only override didReceive request: contentHandler: as shown in the example.

If you plan on downloading non-SSL urls please be sure to enable App Transport Security Settings -> Allow Arbitrary Loads -> true in your plist. See plist example here.

Configure your APNS payload

Then, when sending notifications via APNS:

  • Include the mutable-content flag in your payload aps entry (this key must be present in the aps payload or the system will not call your app extension)
  • Add the ct_mediaUrl and ct_mediaType key-values (or your custom key-values) to the payload, outside of the aps entry.
{
    "aps": {
        "alert": {
      		"body": "test message",
      		"title": "test title",
   	  	},
        "mutable-content": 1,
   	},
    "ct_mediaType": "gif",
    "ct_mediaUrl": "https://www.wired.com/images_blogs/design/2013/09/davey1_1.gif",
	...
}

𝌡 Example Usage

🆕 Change Log

Refer to the CTNotificationService Change Log here.

ctnotificationservice's People

Contributors

aditi3 avatar aishwaryananna avatar nishant-clevertap avatar pwilkniss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ctnotificationservice's Issues

Not able to receive image in notification bar

I have integrated CleverTap having one issue :
Not able to receive image in notification. Application able to receive text notification but when I tried to send notification with image , able to receive notification but image not showing

Here is my configuration

"clevertap-react-native": "^0.4.5",

pod file :
target 'NotificationService' do
platform :ios, '10.0'
pod 'CTNotificationService'
end

NotificationService.h
//
// NotificationService.h
// NotificationService
//
// Created by Pegasus on 17/11/20.
// Copyright © 2020 Facebook. All rights reserved.
//
#import <CTNotificationService/CTNotificationService.h>

@interface NotificationService : CTNotificationServiceExtension

@EnD

NotificationService.m
#import "NotificationService.h"

@implementation NotificationService

  • (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {

    self.mediaUrlKey = @"myMediaUrlKey";
    self.mediaTypeKey = @"myMediaTypeKey";

    [super didReceiveNotificationRequest:request withContentHandler:contentHandler];
    }

@EnD

Can anyone please guide.
IMG_0339

Error Report Privacy Manifests

I encountered an error when generating the privacy report:

Errors EncounteredMissing an expected key: 'NSPrivacyCollectedDataTypes'<redacted>.app/PlugIns/ClevertapNotificationServiceExtension.appex/CTNotificationService.bundle/PrivacyInfo.xcprivacy

introduced PrivacyInfo.xcprivacy in this change #32. I think you should create an empty xcprivacy file. For example, see here.

Push notification not receiving even when app is closed

Hi,

How can we get notification even when app is closed by swipe?

Below are the Android device details: (displaying in Samsung even app closed)
Model: CPH1729 (OPPO),
OS Version: 7.1.1

Not all devices only some specific devices as above...How can we resolve this issue?...

Build Fails in iOS

Hi @Aditi3

when running in the simulator it works fine.
When the archive is made, I get the following errors and warnings and the build fails.

warning:
Target 'Pods-CTNotificationServiceExtension' of project 'Pods' was rejected as an implicit dependency for 'libPods-CTNotificationServiceExtension.a' because its architectures 'arm64' didn't contain all required architectures 'armv7 arm64'

warning:
directory not found for option '-L/Users/user/Library/Developer/Xcode/DerivedData/project-aohgwbgewxccmbdjykjtpkbxkqdp/Build/Intermediates.noindex/ArchiveIntermediates/project/BuildProductsPath/Release-iphoneos/CTNotificationService'

error:
ld: library not found for -lCTNotificationService

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Originally posted by @Arun-paramasivam in #14 (comment)

Image not showing in push notification

Hi,

In iOS, on some devices notification image not showing...Plz let we know what went wrong for the same.

showing in iOS version: 11.4.1 but not showing in iOS version: 11.2.5,

CleverTap sdk version: "clevertap-react-native": "^0.2.1",

If available provide me "react-native" clevertap push notification demo app...

Add SPM support

Hello! More and more teams prefer to use SPM in their projects and we are no exception.
As I understand it, CTNotificationService does not support this dependency manager at the moment. It would be great if you could add support for it.

At the moment I am getting this error. Of course.

CleanShot 2021-09-06 at 23 30 01@2x

Not work with Firebase

I'm using cloud messaging for rich push notifications as well but I can't config the CTNotificationService for it. How can I make it works with Firebase?

Image not showing in list Notification in first open

Describe the bug

following function to show list notification, first open list notification image not showing but the second open image is showing, maybe my code is not correct, please help me, thanks 🙏

============== this my code to show list notification ==============

private func appInboxAction() {
     CleverTap.sharedInstance()?.initializeInbox(callback: ({ success in
            let messageCount = CleverTap.sharedInstance()?.getInboxMessageCount()
            let unreadCount = CleverTap.sharedInstance()?.getInboxMessageUnreadCount()
            if success {
                let style = CleverTapInboxStyleConfig()
                style.title = "Notifications"
                style.navigationTintColor = UIColor.primary

                if let inboxController = CleverTap.sharedInstance()?.newInboxViewController(with: style, andDelegate: self) {
                    let navigationController = UINavigationController.init(rootViewController: inboxController)
                    self.present(navigationController, animated: true, completion: nil)
                }
            }
        }))
 }

Screenshots
============== first ==============
Screen Shot 2022-01-18 at 15 05 54

============== seconds ==============
Screen Shot 2022-01-18 at 15 06 08

`shared` is unavailable in application extensions for iOS

I haven't seen any issues created related to this, but I cannot get the project to build with the following error:
'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.

I have assigned the same appApp Group to both the extension, and the main project, with no luck. How do I get around this?

Library not found for -lCTNotificationService

ld: library not found for -lCTNotificationService
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I followed the installation guideline.

Platform: React Native
OS: iOS

Pod file.

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'

target 'SampleApp' do
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change false to true and then install pods
:hermes_enabled => true
)

pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'
pod 'GoogleTagManager'

target 'SampleAppTests' do
inherit! :complete
# Pods for testing
end

post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
end
end

target 'NotificationService' do
pod "CTNotificationService"
end

I tried adding libCTNotificationService.a in buildPhase->Link binary with libraries.
I hope Xcode not able to find the Path to CTNotificationService.

Can someone help me here?

iOS Rich Push Notifications delegates are not calling & content is not showing.

@Aditi3 Happy Independence from India 🇮🇳

I am facing an issue while implementing `iOS Rich Push Notifications
Implemented all the steps properly also two individuals identifier for notification on Apple developer account.

Added an app group & Pust Notification capability. Removed viewController from MainInterface and added View as per documentation

Also, you can check the attachment for the implementation.

But when I triggered the notification through .apns file content on the simulator there is no methods or delegates getting triggered.

Please guide me on what I am missing any steps or doing wrong.

Getting issue in integrating notification extension service using clevertap

is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
if (![[UIApplication sharedApplication] canOpenURL:testURL]) {
^
In module 'UIKit' imported from /Users/manish.kumar/Desktop/MarketPlace/marketplaceapp/ios/Pods/Target Support Files/AppAuth/AppAuth-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:87:54: note: property 'sharedApplication' is declared unavailable here
@Property(class, nonatomic, readonly) UIApplication *sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead.");
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:87:54: note: 'sharedApplication' has been explicitly marked unavailable here
/Users/manish.kumar/Desktop/MarketPlace/marketplaceapp/ios/Pods/AppAuth/Sources/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m:148:23: error: 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
[[UIApplication sharedApplication] openURL:_appStoreURL];
^
In module 'UIKit' imported from /Users/manish.kumar/Desktop/MarketPlace/marketplaceapp/ios/Pods/Target Support Files/AppAuth/AppAuth-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:87:54: note: property 'sharedApplication' is declared unavailable here
@Property(class, nonatomic, readonly) UIApplication *sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead.");
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:87:54: note: 'sharedApplication' has been explicitly marked unavailable here
/Users/manish.kumar/Desktop/MarketPlace/marketplaceapp/ios/Pods/AppAuth/Sources/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m:148:42: warning: 'openURL:' is deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
[[UIApplication sharedApplication] openURL:_appStoreURL];
^~~~~~~
openURL:options:completionHandler:
In module 'UIKit' imported from /Users/manish.kumar/Desktop/MarketPlace/marketplaceapp/ios/Pods/Target Support Files/AppAuth/AppAuth-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:97:1: note: 'openURL:' has been explicitly marked deprecated here

  • (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0, 10.0)) API_UNAVAILABLE(visionos);
    ^
    /Users/manish.kumar/Desktop/MarketPlace/marketplaceapp/ios/Pods/AppAuth/Sources/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m:156:42: error: 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
    BOOL openedInBrowser = [[UIApplication sharedApplication] openURL:requestURL];
    ^
    In module 'UIKit' imported from /Users/manish.kumar/Desktop/MarketPlace/marketplaceapp/ios/Pods/Target Support Files/AppAuth/AppAuth-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:87:54: note: property 'sharedApplication' is declared unavailable here
    @Property(class, nonatomic, readonly) UIApplication *sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead.");
    ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:87:54: note: 'sharedApplication' has been explicitly marked unavailable here
    /Users/manish.kumar/Desktop/MarketPlace/marketplaceapp/ios/Pods/AppAuth/Sources/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m:156:61: warning: 'openURL:' is deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
    BOOL openedInBrowser = [[UIApplication sharedApplication] openURL:requestURL];
    ^~~~~~~
    openURL:options:completionHandler:
    In module 'UIKit' imported from /Users/manish.kumar/Desktop/MarketPlace/marketplaceapp/ios/Pods/Target Support Files/AppAuth/AppAuth-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:97:1: note: 'openURL:' has been explicitly marked deprecated here
  • (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0, 10.0)) API_UNAVAILABLE(visionos);
    ^
    2 warnings and 3 errors generated.

No such module 'CTNotificationService'

I am getting the below error when I build my iOS project in Xcode 13.0 for Simulator 15 with Swift 5.5, Apple M1 Silicon.

All other dependencies, including the main CleverTap SDK, are working properly after the update; the issue is only with the notifications extension.

Screen Shot 2022-04-10 at 7 15 44 PM

Issue updating to 0.1.6

When trying to update to version 0.1.6, I'm getting this error:

[!] CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/8/8/4/CTNotificationService/0.1.6/CTNotificationService.podspec.json Response: Failure when receiving data from the peer

Works well with version 0.1.5

Image not showing in push notification in iOS

Hi,
I'm using

  • clevertap-react-native (0.4.5):
    • CleverTap-iOS-SDK (~> 3.8.2)
    • React
    • CTNotificationService (0.1.2)

I'm receiving push notifications in both android and ios. But push with images works only on android. In iOS I receive a notification but the image is not shown. The title of the message comes as 'Test Push [modified]'. Some extra data is coming but not sure why the image is not shown.
Have set the deployment target of the Notification Service Extension file as 10.0. And I'm testing it on iPhone 6 with ios 13.7.

WhatsApp Image 2020-09-26 at 11 16 10 PM

Originally posted by @Arun-paramasivam in #3 (comment)

Build error on running in simulator

When run on real device there are no issues but when trying to run on simulator, we are facing the below build error in NotificationService extension. Tried every possible solution found in stackoverflow but in vain.

ld: framework not found CTNotificationService
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Can we fetch location at notification receiving time

Hi,

How can we get location geo at the time of notification receive and send to server even when app is closed???. or How can we send silent notification to wakeup the App?? in Android.

If any solution for the same...Plz let we know...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.