{"payload":{"allShortcutsEnabled":false,"fileTree":{"docs/ios/messaging-main/push-messaging":{"items":[{"name":"assets","path":"docs/ios/messaging-main/push-messaging/assets","contentType":"directory"},{"name":"c-set-up-rich-push-notif-ios.md","path":"docs/ios/messaging-main/push-messaging/c-set-up-rich-push-notif-ios.md","contentType":"file"},{"name":"c-troubleshooting-push-messaging.md","path":"docs/ios/messaging-main/push-messaging/c-troubleshooting-push-messaging.md","contentType":"file"},{"name":"push-messaging.md","path":"docs/ios/messaging-main/push-messaging/push-messaging.md","contentType":"file"},{"name":"t-mob-imp-push-deeplinking-ios-4x.md","path":"docs/ios/messaging-main/push-messaging/t-mob-imp-push-deeplinking-ios-4x.md","contentType":"file"}],"totalCount":5},"docs/ios/messaging-main":{"items":[{"name":"messaging","path":"docs/ios/messaging-main/messaging","contentType":"directory"},{"name":"push-messaging","path":"docs/ios/messaging-main/push-messaging","contentType":"directory"},{"name":"messaging-main.md","path":"docs/ios/messaging-main/messaging-main.md","contentType":"file"}],"totalCount":3},"docs/ios":{"items":[{"name":"acquisition-main","path":"docs/ios/acquisition-main","contentType":"directory"},{"name":"amm","path":"docs/ios/amm","contentType":"directory"},{"name":"analytics-main","path":"docs/ios/analytics-main","contentType":"directory"},{"name":"apple-tv-implementation-tvos","path":"docs/ios/apple-tv-implementation-tvos","contentType":"directory"},{"name":"c-mob-privacy-gdpr-ios","path":"docs/ios/c-mob-privacy-gdpr-ios","contentType":"directory"},{"name":"configuration","path":"docs/ios/configuration","contentType":"directory"},{"name":"getting-started","path":"docs/ios/getting-started","contentType":"directory"},{"name":"ios-ext","path":"docs/ios/ios-ext","contentType":"directory"},{"name":"location","path":"docs/ios/location","contentType":"directory"},{"name":"marketing-cloud","path":"docs/ios/marketing-cloud","contentType":"directory"},{"name":"messaging-main","path":"docs/ios/messaging-main","contentType":"directory"},{"name":"phonegap","path":"docs/ios/phonegap","contentType":"directory"},{"name":"reference","path":"docs/ios/reference","contentType":"directory"},{"name":"target-main","path":"docs/ios/target-main","contentType":"directory"},{"name":"apple-watch-implementation-watchkit.md","path":"docs/ios/apple-watch-implementation-watchkit.md","contentType":"file"},{"name":"metrics.md","path":"docs/ios/metrics.md","contentType":"file"},{"name":"overview.md","path":"docs/ios/overview.md","contentType":"file"},{"name":"rel-notes.md","path":"docs/ios/rel-notes.md","contentType":"file"}],"totalCount":18},"docs":{"items":[{"name":"android","path":"docs/android","contentType":"directory"},{"name":"blackberry","path":"docs/blackberry","contentType":"directory"},{"name":"ios","path":"docs/ios","contentType":"directory"},{"name":"unity","path":"docs/unity","contentType":"directory"},{"name":"universal-windows","path":"docs/universal-windows","contentType":"directory"},{"name":"windows-appstore","path":"docs/windows-appstore","contentType":"directory"},{"name":"xamarin","path":"docs/xamarin","contentType":"directory"}],"totalCount":7},"":{"items":[{"name":"docs","path":"docs","contentType":"directory"},{"name":"samples","path":"samples","contentType":"directory"},{"name":"sdks","path":"sdks","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":".npmignore","path":".npmignore","contentType":"file"},{"name":"LICENSE.md","path":"LICENSE.md","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"package.json","path":"package.json","contentType":"file"},{"name":"plugin.xml","path":"plugin.xml","contentType":"file"}],"totalCount":9}},"fileTreeProcessingTime":12.902108,"foldersToFetch":[],"repo":{"id":16493963,"defaultBranch":"master","name":"mobile-services","ownerLogin":"Adobe-Marketing-Cloud","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2014-02-03T21:43:40.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/1440554?v=4","public":true,"private":false,"isOrgOwned":true},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1618423338.265981","canEdit":false,"refType":"branch","currentOid":"bf5c2668ebc79218b2ddf4694ff9952fa52be892"},"path":"docs/ios/messaging-main/push-messaging/push-messaging.md","currentUser":null,"blob":{"rawLines":null,"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/Adobe-Marketing-Cloud/mobile-services/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"push-messaging.md","displayUrl":"https://github.com/Adobe-Marketing-Cloud/mobile-services/blob/master/docs/ios/messaging-main/push-messaging/push-messaging.md?raw=true","headerInfo":{"blobSize":"12.6 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"723cfb3","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2FAdobe-Marketing-Cloud%2Fmobile-services%2Fblob%2Fmaster%2Fdocs%2Fios%2Fmessaging-main%2Fpush-messaging%2Fpush-messaging.md%3Flang%3Des-ES","isCSV":false,"isRichtext":true,"toc":[{"level":1,"text":"Push messaging","anchor":"push-messaging","htmlText":"Push messaging"},{"level":2,"text":"Prerequisites","anchor":"prerequisites","htmlText":"Prerequisites"},{"level":2,"text":"Enabling push messaging","anchor":"enabling-push-messaging","htmlText":"Enabling push messaging"},{"level":2,"text":"Example","anchor":"example","htmlText":"Example"}],"lineInfo":{"truncatedLoc":"244","truncatedSloc":"202"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"Markdown","languageID":222,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/Adobe-Marketing-Cloud/mobile-services/blob/master/docs/ios/messaging-main/push-messaging/push-messaging.md?lang=es-ES","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/Adobe-Marketing-Cloud/mobile-services/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/Adobe-Marketing-Cloud/mobile-services/raw/master/docs/ios/messaging-main/push-messaging/push-messaging.md","renderImageOrRaw":false,"richText":"

Push messaging

\n

Adobe Mobile and the Adobe Mobile SDK allow you to send push messages to your users. The SDK also allows you to easily report users who have opened your app as a result of clicking through a push message.

\n
\n

Important: The information in this topic is a suggestion for a possible implementation. We strongly recommend that you review Apple's iOS documentation to determine the best implementation for your app. Your implementation should be determined by the frameworks that you are using, and the versions of iOS that your app will target.

\n
\n

To use push messaging, you must have SDK version 4.6 or later.

\n
\n

Important: Do not manually set the Experience Cloud ID inside your app. This causes the creation of a new unique user that will not receive push messages because of its opt-in status. For example, suppose a user that has opt-ed in to receive push messages logs in to your app. After logging in, if you manually set the ID inside your app, a new unique user is created that has not opted to receive push messages. This new user will not receive your push messages.

\n
\n

Prerequisites

\n\n
\n

Important: Moving your app to a new report suite is not supported. If you migrate to a new report suite, your push configuration can break, and messages might not be sent.

\n
\n

Enabling push messaging

\n
    \n
  1. \n

    Verify that the ADBMobileConfig.json file contains the required settings for push messaging.

    \n

    The \"marketingCloud\" object must have its \"org\" property configured for push messaging.

    \n
    \"marketingCloud\": { \n    \"org\": \"3CE342C92046435B0A490D4C@AdobeOrg\" \n}
    \n
  2. \n
  3. \n

    Import the library in your AppDelegate.

    \n
    #import \"ADBMobile.h\"
    \n
  4. \n
  5. \n

    To determine the settings for which your app needs to ask for permission, review Configuring Remote Notification Support.

    \n

    Here is an example of a possible implementation that is asking for permission to use Alerts, Badges, Sounds, and Remote notification:

    \n
    // iOS 10 and newer \nif (NSClassFromString(@\"UNUserNotificationCenter\")) { \n    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];   \n    [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge) \n        completionHandler:^(BOOL granted, NSError * _Nullable error) { \n        if (granted) { NSLog(@\"authorization given\"); } \n        else { NSLog(@\"authorization rejected\"); } \n        if (error) { NSLog(@\"error during authorization: %@\", error.localizedDescription); } \n    }]; \n    // have to ask for permission for remote notifications separately  \n    [application registerForRemoteNotifications]; \n    // make this class the delegate for user notification handling  \n    center.delegate = self; \n} \n// iOS 8.0 to iOS 9.3.5 \nelse if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { \n#pragma GCC diagnostic push \n#pragma GCC diagnostic ignored \"-Wdeprecated-declarations\" \n    UIUserNotificationTypetypes = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge| UIUserNotificationTypeSound; \n    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; \n    [application registerUserNotificationSettings:settings]; \n    // have to ask for permission for remote notifications separately  \n    [application registerForRemoteNotifications]; \n} \n// older than iOS 8.0  \nelse { \n    [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge| UIRemoteNotificationTypeSound];  \n#pragma GCC diagnostic pop \n}
    \n
  6. \n
  7. \n

    The push token must be passed to the SDK using the setPushIdentifier: method in ADBMobile class.

    \n
    - (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { \n    ... \n    [ADBMobile setPushIdentifier:deviceToken]; \n    ... \n}
    \n
  8. \n
  9. \n

    To determine the correct implementation for your environment, go to UserNotifications.

    \n

    This step helps you enable push reporting by passing the userInfo dictionary to the SDK when the user opens the app by using click-through of a push message.

    \n

    The following code sample is an example of a possible implementation:

    \n
    // device running < iOS 7 \n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { \n    // only send the hit if the app is inactive \n    if (application.applicationState == UIApplicationStateInactive) {  \n        [ADBMobile trackPushMessageClickThrough:userInfo]; \n    } \n} \n// device running between iOS 7 and iOS 9.3.5 \n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult)) completionHandler { \n    // only send the hit if the app is inactive \n    if (application.applicationState == UIApplicationStateInactive) { \n        // only run this code if the UNUserNotificationCenterclass is not available or its delegate is not set (pre iOS 10) \n        if (!NSClassFromString(@\"UNUserNotificationCenter\") || ![UNUserNotificationCenter currentNotificationCenter].delegate) {  \n            [ADBMobiletrackPushMessageClickThrough:userInfo]; \n        } \n    } \n    completionHandler(UIBackgroundFetchResultNoData); \n} \n// device running >= iOS 10 \n- (void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { \n    if ([response.notification.request.trigger isKindOfClass:UNPushNotificationTrigger.class]) { \n        [ADBMobile trackPushMessageClickThrough:response.notification.request.content.userInfo]; \n    } \n    completionHandler(); \n}
    \n
  10. \n
  11. \n

    To keep your estimated push audience accurate, notify the SDK when a user manually disables push messaging for your app by calling [ADBMobile setPushIdentifier: nil] in the applicationDidBecomeActive: method in your AppDelegate.

    \n
    // device running < iOS 7 \n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { \n    // only send the hit if the app is inactive \n    if (application.applicationState == UIApplicationStateInactive) {  \n        [ADBMobile trackPushMessageClickThrough:userInfo]; \n    } \n} \n// device running between iOS 7 and iOS 9.3.5 \n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult)) completionHandler { \n    // only send the hit if the app is inactive \n    if (application.applicationState == UIApplicationStateInactive) { \n        // only run this code if the UNUserNotificationCenterclass is not available or its delegate is not set (pre iOS 10) \n        if (!NSClassFromString(@\"UNUserNotificationCenter\") || ![UNUserNotificationCenter currentNotificationCenter].delegate) {  \n            [ADBMobiletrackPushMessageClickThrough:userInfo]; \n        } \n    } \n    completionHandler(UIBackgroundFetchResultNoData); \n} \n// device running >= iOS 10 \n- (void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { \n    if ([response.notification.request.trigger isKindOfClass:UNPushNotificationTrigger.class]) { \n        [ADBMobile trackPushMessageClickThrough:response.notification.request.content.userInfo]; \n    } \n    completionHandler(); \n}
    \n
  12. \n
\n

Example

\n

The following is an example of what an AppDelegate.m implementation might look like:

\n
#import \"AppDelegate.h\" \n#import \"ADBMobile.h\" \n \n@implementation AppDelegate \n  \n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { \n    if (NSClassFromString(@\"UNUserNotificationCenter\")) { \n        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; \n        [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge) \n                              completionHandler:^(BOOL granted, NSError * _Nullable error) {  \n            if (granted) { NSLog(@\"authorization given\"); } \n            else { NSLog(@\"authorization rejected\"); } \n            if (error) { NSLog(@\"error during authorization: %@\", error.localizedDescription); } \n        }]; \n        center.delegate = self; \n        [application registerForRemoteNotifications]; \n    } \n    else if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { \n#pragma GCC diagnostic push \n#pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"  \n        UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge| UIUserNotificationTypeSound; \n        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; \n        [application registerUserNotificationSettings:settings];  \n        [application registerForRemoteNotifications]; \n    } \n    else { \n        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert| UIRemoteNotificationTypeBadge| UIRemoteNotificationTypeSound]; \n#pragma GCC diagnostic pop \n    } \n \n    return YES; \n} \n \n- (void) applicationDidBecomeActive:(UIApplication *)application {  \n    if (NSClassFromString(@\"UNUserNotifcationCenter\")) { \n        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; \n        [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { \n            if (settings.authorizationStatus != UNAuthorizationStatusAuthorized) {  \n                [ADBMobile setPushIdentifier:nil]; \n            } \n        }]; \n    } \n#pragma GCC diagnostic push \n#pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"  \n    else if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) { \n        if (![application isRegisteredForRemoteNotifications]) {  \n            [ADBMobile setPushIdentifier:nil]; \n        } \n    } \n    else if ([application enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) { \n        [ADBMobile setPushIdentifier:nil]; \n    } \n#pragma GCC diagnostic pop \n} \n \n- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { \n    [ADBMobile setPushIdentifier:deviceToken]; \n} \n \n- (void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { \n    [ADBMobile setPushIdentifier:nil]; \n} \n \n- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { \n    if (application.applicationState == UIApplicationStateInactive) {  \n        [ADBMobile trackPushMessageClickThrough:userInfo];  \n    } \n} \n \n- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { \n    if (application.applicationState == UIApplicationStateInactive) {  \n        if (!NSClassFromString(@\"UNUserNotificationCenter\") || ![UNUserNotificationCenter currentNotificationCenter].delegate) {  \n            [ADBMobile trackPushMessageClickThrough:userInfo]; \n        } \n    } \n \n    completionHandler(UIBackgroundFetchResultNoData); \n} \n \n- (void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { \n    if ([response.notification.request.trigger isKindOfClass:UNPushNotificationTrigger.class]) { \n        [ADBMobile trackPushMessageClickThrough:response.notification.request.content.userInfo]; \n    } \n \n    completionHandler(); \n} \n \n@end
\n
","renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":{"timed_out":false,"not_analyzed":false,"symbols":[{"name":"Push messaging","kind":"section_1","ident_start":2,"ident_end":16,"extent_start":0,"extent_end":12893,"fully_qualified_name":"Push messaging","ident_utf16":{"start":{"line_number":0,"utf16_col":2},"end":{"line_number":0,"utf16_col":16}},"extent_utf16":{"start":{"line_number":0,"utf16_col":0},"end":{"line_number":244,"utf16_col":0}}},{"name":"Prerequisites","kind":"section_2","ident_start":1106,"ident_end":1119,"extent_start":1103,"extent_end":1678,"fully_qualified_name":"Prerequisites","ident_utf16":{"start":{"line_number":10,"utf16_col":3},"end":{"line_number":10,"utf16_col":16}},"extent_utf16":{"start":{"line_number":10,"utf16_col":0},"end":{"line_number":22,"utf16_col":0}}},{"name":"Enabling push messaging","kind":"section_2","ident_start":1681,"ident_end":1704,"extent_start":1678,"extent_end":8529,"fully_qualified_name":"Enabling push messaging","ident_utf16":{"start":{"line_number":22,"utf16_col":3},"end":{"line_number":22,"utf16_col":26}},"extent_utf16":{"start":{"line_number":22,"utf16_col":0},"end":{"line_number":150,"utf16_col":0}}},{"name":"Example","kind":"section_2","ident_start":8532,"ident_end":8539,"extent_start":8529,"extent_end":12893,"fully_qualified_name":"Example","ident_utf16":{"start":{"line_number":150,"utf16_col":3},"end":{"line_number":150,"utf16_col":10}},"extent_utf16":{"start":{"line_number":150,"utf16_col":0},"end":{"line_number":244,"utf16_col":0}}}]}},"copilotInfo":null,"copilotAccessAllowed":false,"csrf_tokens":{"/Adobe-Marketing-Cloud/mobile-services/branches":{"post":"ah-zLEsonEnehxrqLn9W8G1vQFPqLjGiRe76jsIXnZ8W4B-EclHCdizM67smCimZM_DS8XbrgRXq4O-NMoZMNw"},"/repos/preferences":{"post":"h3l8CP1romt3-ynslfx3gg-ifmFHVi8bwzw_gXRm_P5SkMD07taGHPA5JZjtX79xXf-OvY_uMGO6auVkuw1D9w"}}},"title":"mobile-services/docs/ios/messaging-main/push-messaging/push-messaging.md at master ยท Adobe-Marketing-Cloud/mobile-services"}