Skip to content

Commit

Permalink
Merge pull request #5 from yandexmobile/release-0.7.0
Browse files Browse the repository at this point in the history
release-0.7.0: AppMetrica Push SDK release 0.7.0
TGIshib authored Sep 3, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 8c20ef7 + d631756 commit f475c94
Showing 13 changed files with 590 additions and 19 deletions.
6 changes: 6 additions & 0 deletions Examples/ObjectiveC/Podfile
Original file line number Diff line number Diff line change
@@ -7,3 +7,9 @@ target 'YandexMobileMetricaPushSampleObjC' do
pod 'YandexMobileMetricaPush'

end

target 'YandexMobileMetricaPushNotificationServiceExtenstionSampleObjC' do

pod 'YandexMobileMetricaPush'

end
18 changes: 9 additions & 9 deletions Examples/ObjectiveC/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
PODS:
- YandexMobileMetrica (3.0.0):
- YandexMobileMetrica/Static (= 3.0.0)
- YandexMobileMetrica/Static (3.0.0)
- YandexMobileMetricaPush (0.6.0):
- YandexMobileMetricaPush/Static (= 0.6.0)
- YandexMobileMetricaPush/Static (0.6.0):
- YandexMobileMetrica (3.2.0):
- YandexMobileMetrica/Static (= 3.2.0)
- YandexMobileMetrica/Static (3.2.0)
- YandexMobileMetricaPush (0.7.0):
- YandexMobileMetricaPush/Static (= 0.7.0)
- YandexMobileMetricaPush/Static (0.7.0):
- YandexMobileMetrica (~> 3.0)

DEPENDENCIES:
- YandexMobileMetrica
- YandexMobileMetricaPush

SPEC CHECKSUMS:
YandexMobileMetrica: 8dcf67ce99c73f351c55b5a21cff1e1f56b706e0
YandexMobileMetricaPush: 973073e69b63c9c3ec45ccb1fbfecd997538650a
YandexMobileMetrica: f18374ee6977a4cd1d0a86298a0df4ad7baf4135
YandexMobileMetricaPush: 43d7c6bbaeee637418a8d3c287af93df1fb512d5

PODFILE CHECKSUM: b3e8be638ddfaf8be416cb8ec31ecb57ed3069ce
PODFILE CHECKSUM: cc8115f2d2fb9083ae9a67cafb01c0893499d128

COCOAPODS: 1.4.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>YandexMobileMetricaPushNotificationServiceExtenstionSampleObjC</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>NotificationService</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// NotificationService.h
//
// This file is a part of the AppMetrica
//
// Version for iOS © 2018 YANDEX
//
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://yandex.com/legal/metrica_termsofuse/
//

#import <UserNotifications/UserNotifications.h>

@interface NotificationService : UNNotificationServiceExtension

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// NotificationService.m
//
// This file is a part of the AppMetrica
//
// Version for iOS © 2018 YANDEX
//
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://yandex.com/legal/metrica_termsofuse/
//

#import "NotificationService.h"
#import <YandexMobileMetricaPush/YandexMobileMetricaPush.h>

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];

[YMPYandexMetricaPush setExtensionAppGroup:@"EXTENSION_AND_APP_SHARED_APP_GROUP_NAME"];
[YMPYandexMetricaPush handleDidReceiveNotificationRequest:request];

self.contentHandler(self.bestAttemptContent);
}

- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
self.contentHandler(self.bestAttemptContent);
}

@end

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Replace API_KEY with your unique API key. Please, read official documentation to find out how to obtain one:
// https://tech.yandex.com/metrica-mobile-sdk/doc/mobile-sdk-dg/tasks/ios-quickstart-docpage/
[YMMYandexMetrica activateWithConfiguration:[[YMMYandexMetricaConfiguration alloc] initWithApiKey:@"API_KEY"]];
[YMPYandexMetricaPush setExtensionAppGroup:@"EXTENSION_AND_APP_SHARED_APP_GROUP_NAME"];

// Enable in-app push notifications handling in iOS 10
if ([UNUserNotificationCenter class] != Nil) {
@@ -51,6 +52,13 @@ - (void)registerForPushNotificationsWithApplication:(UIApplication *)application
UNAuthorizationOptionBadge |
UNAuthorizationOptionSound;
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNNotificationCategory *category = [UNNotificationCategory
categoryWithIdentifier:@"Custom category"
actions:@[]
intentIdentifiers:@[]
options:UNNotificationCategoryOptionCustomDismissAction];
// Only for push notifications of this category dismiss action will be tracked.
[center setNotificationCategories:[NSSet setWithObject:category]];
[center requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError *error) {
// Enable or disable features based on authorization.
}];
6 changes: 6 additions & 0 deletions Examples/Swift/Podfile
Original file line number Diff line number Diff line change
@@ -14,3 +14,9 @@ target 'YandexMobileMetricaPushSampleSwift' do
pod 'YandexMobileMetricaPush'

end

target 'YandexMobileMetricaPushNotificationServiceExtenstionSampleSwift' do

pod 'YandexMobileMetricaPush'

end
18 changes: 9 additions & 9 deletions Examples/Swift/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
PODS:
- YandexMobileMetrica (3.0.0):
- YandexMobileMetrica/Static (= 3.0.0)
- YandexMobileMetrica/Static (3.0.0)
- YandexMobileMetricaPush (0.6.0):
- YandexMobileMetricaPush/Static (= 0.6.0)
- YandexMobileMetricaPush/Static (0.6.0):
- YandexMobileMetrica (3.2.0):
- YandexMobileMetrica/Static (= 3.2.0)
- YandexMobileMetrica/Static (3.2.0)
- YandexMobileMetricaPush (0.7.0):
- YandexMobileMetricaPush/Static (= 0.7.0)
- YandexMobileMetricaPush/Static (0.7.0):
- YandexMobileMetrica (~> 3.0)

DEPENDENCIES:
- YandexMobileMetrica
- YandexMobileMetricaPush

SPEC CHECKSUMS:
YandexMobileMetrica: 8dcf67ce99c73f351c55b5a21cff1e1f56b706e0
YandexMobileMetricaPush: 973073e69b63c9c3ec45ccb1fbfecd997538650a
YandexMobileMetrica: f18374ee6977a4cd1d0a86298a0df4ad7baf4135
YandexMobileMetricaPush: 43d7c6bbaeee637418a8d3c287af93df1fb512d5

PODFILE CHECKSUM: 138d02e69e9ea0891c989cd6e2622af9fc74675f
PODFILE CHECKSUM: 77beec3b141cf23c0e068dd9c985355b5e453991

COCOAPODS: 1.4.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>YandexMobileMetricaPushNotificationServiceExtenstionSampleSwift</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// NotificationService.swift
//
// This file is a part of the AppMetrica
//
// Version for iOS © 2018 YANDEX
//
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://yandex.com/legal/metrica_termsofuse/
//

import UserNotifications
import YandexMobileMetricaPush

class NotificationService: UNNotificationServiceExtension {

var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...

YMPYandexMetricaPush.setExtensionAppGroup("EXTENSION_AND_APP_SHARED_APP_GROUP_NAME")
YMPYandexMetricaPush.handleDidReceive(request)

contentHandler(bestAttemptContent)
}
}

override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Replace API_KEY with your unique API key. Please, read official documentation to find out how to obtain one:
// https://tech.yandex.com/metrica-mobile-sdk/doc/mobile-sdk-dg/tasks/swift-quickstart-docpage/
YMMYandexMetrica.activate(with: YMMYandexMetricaConfiguration(apiKey: "API_KEY")!)
YMPYandexMetricaPush.setExtensionAppGroup("EXTENSION_AND_APP_SHARED_APP_GROUP_NAME")

// Enable in-app push notifications handling in iOS 10
if #available(iOS 10.0, *) {
@@ -49,6 +50,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
if #available(iOS 10.0, *) {
// iOS 10.0 and above
let center = UNUserNotificationCenter.current()
let category = UNNotificationCategory(identifier: "Custom category",
actions: [],
intentIdentifiers: [],
options:UNNotificationCategoryOptions.customDismissAction)
// Only for push notifications of this category dismiss action will be tracked.
center.setNotificationCategories(Set([category]))
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}

0 comments on commit f475c94

Please sign in to comment.