I found little snippet from twitter about how to know if application is installed via TestFlight.
Here, appStoreReceiptURL
is an instance property, which we can find from main bundle.
Here, I am adding snippet for both Objective-C and Swift.
iOS
Tutorial : Let's take quick dive in Grouped Notifications - iOS 12
With iOS 12 we can set the group of notifications
Thread Identifier
Create notification content with threadIdentifier
to create group of that notification. Group will be of the application or specific topic from an application.
1 2 3 4 5 |
// Creating Groups with Thread Identifiers let content = UNMutableNotificationContent() content.title = "Notifications Group" content.body = "Tutorial by Ashish Kakkad" content.threadIdentifier = "notify-team-ios" |
Notification payload will be like this
1 2 3 4 5 6 7 8 9 |
{ "aps" : { "alert" : { "title" : "Notifications Group", "body" : "Tutorial by Ashish Kakkad" } "thread-id" : "notify-team-ios" } } |
Give meaningful name to thread identifier for specific purpose of group.
Summary of group
Simple Notification Group Summary
1 2 |
let summaryFormat = "%u more messages" return UNNotificationCategory(identifier: "category-identifier", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: nil, categorySummaryFormat: summaryFormat, options: []) |
Hidden Previews Summary Customization
1 2 3 |
let summaryFormat = "%u more messages" let hiddenPreviewsPlaceholder = "%u messages" return UNNotificationCategory(identifier: "category-identifier", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenPreviewsPlaceholder, categorySummaryFormat: summaryFormat, options: []) |
Notification Group Summary with Arguments
1 2 |
let summaryFormat = "%u more messages from %@" return UNNotificationCategory(identifier: "group-messages", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: nil, categorySummaryFormat: summaryFormat, options: []) |
Notification Group Summary Argument
1 2 3 4 |
let content = UNMutableNotificationContent() content.body = "…" content.threadIdentifier = "notify-team-ios" content.summaryArgument = "Ashish" |
Notification Summary with Argument Count
1 2 3 4 5 |
let content = UNMutableNotificationContent() content.body = "…" content.threadIdentifier = "notify-team-ios" content.summaryArgument = "Ashish" content.summaryArgumentCount = 2 |
Updated notification payload will be like this
1 2 3 4 5 6 7 8 9 10 |
{ "aps" : { "alert" : { "body" : "…", "summary-arg" : "Ashish", "summary-arg-count" : 2 }, "thread-id" : "notify-team-ios" } } |
Example with local notifications:
Setup user notifications in the application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
// // AppDelegate.swift // AKGroupedNotifications // // Created by Ashish Kakkad on 21/06/18. // Copyright © 2018 Kode. All rights reserved. // import UIKit import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let center = UNUserNotificationCenter.current() center.delegate = self let options: UNAuthorizationOptions = [.alert, .sound] center.requestAuthorization(options: options) { (granted, error) in if !granted { print("Something went wrong") } } center.getNotificationSettings { (settings) in if settings.authorizationStatus != .authorized { // Notifications not allowed } } return true } } extension AppDelegate : UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { completionHandler([.alert, .sound]) } } |
Fire local notifications and look into the thread identifier, summary and summary count…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
if #available(iOS 10.0, *) { for i in 1...5 { let content = UNMutableNotificationContent() content.categoryIdentifier = "AKNotification" content.title = "Notification \(i)" content.body = "\(Date())" if i == 2 { content.threadIdentifier = "ak-notingroup" } else { content.threadIdentifier = "ak-group-website" content.summaryArgumentCount = 1 content.summaryArgument = "by ashishkakkad.com" } let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(10*i), repeats: false) let request = UNNotificationRequest(identifier: "NotificationID\(i)", content: content, trigger: trigger) let center = UNUserNotificationCenter.current() center.add(request) { (error) in print(error?.localizedDescription ?? "") } } } |
Conclusion
I know that I haven’t described anything in detail. If I get time I will update this blog with details.
Happy Coding ?
If you have any questions, comments, suggestions or feedback then contact me on Twitter @ashishkakkad8.
Tips for update CocoaPods and your project libraries
CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects.
CocoaPods is built with Ruby and is installable with the default Ruby available on OS X. We recommend you use the default ruby.
Update your system
Update your system by following command in terminal.
1 |
$ sudo gem update --system |
Above command will install/update rubygems.
Install CocoaPods
Install CocoaPods in your system by following command in terminal.
1 |
$ sudo gem install cocoapods |
If you are getting errors above command then use following command.
1 |
$ sudo gem install -n /usr/local/bin cocoapods |
Check CocoaPods Version
1 |
$ pod --version |
Update CocoaPods Repository
We have to update CocoaPods repository with latest pod updates by developers. Use following command to update CocoaPods repository:
1 |
$ pod repo update |
It will take some time to update all sub repositories.
Update pod for your project
If you directly apply the command pod install then some time new pods will not be updated in your project. For that you have to remove that specific pod information from the pod file and you have to apply pod install command. It will remove pod from the project. After that again you have to add the pod information in the pod file. Again you have to apply pod install command to install new version of pod.
Follow the next steps:
1. Remove SomePod
from the Podfile
2. Run pod install
pods will now remove SomePod
from our project and from the Podfile.lock
file.
3. Put back SomePod
into the Podfile
4. Run pod install
again
This time the latest version of our pod will be installed and saved in the Podfile.lock
.
You can update single pod file as follows:
1 |
$ pod update 'POD_NAME' |
Remove all CocoaPods from a project
Install CocoaPods deintegrate and clean commands from terminal.
1 |
$ sudo gem install cocoapods-deintegrate cocoapods-clean |
Now you have to apply both command to remove all CocoaPods from your project:
1 2 |
$ pod deintegrate $ pod clean |
Happy Coding ?
List of known Xcode issues
Xcode is IDE for development of the iOS, macOS, tvOS and watchOS applications. Every year apple comes up with so many changes in this IDE. Xcode 9.3 released on March 29, 2018.
Here, I am listing out all the issues with the workaround.
Use of Codable and Coding Key with JSONEncoder and JSONDecoder in Swift 4
Codable is added with Xcode 9, iOS 11 and Swift 4. Codable is used to make your data types encodable and decodable for compatibility with external representations such as JSON.
Codable use to support both encoding and decoding, declare conformance to Codable, which combines the Encodable and Decodable protocols. This process is known as making your types codable.
Let’s Take an Example with Structure of Movie, here we have defined the structure as Codable. So, We can encode and decode it easily.
Push Notifications in iOS 10 [Swift]
The new framework called “UserNotifications” is introduced with iOS 10 SDK. The UserNotifications framework (UserNotifications.framework) supports the delivery and handling of local and remote notifications.
So, Let see what we have to change to get the push notifications in iOS 10.
Push Notifications in iOS 10 [Objective-C]
The new framework called “UserNotifications” is introduced with iOS 10 SDK. The UserNotifications framework (UserNotifications.framework) supports the delivery and handling of local and remote notifications. So, Let see what we have to change to get the push notifications in iOS 10.
Steps for implement code to handle push notifications in iOS 10
Import UserNotifications.framework in your AppDelegate file
1 |
#import <UserNotifications/UserNotifications.h> |
Also add UNUserNotificationCenterDelegate.
1 2 3 4 |
#import <UserNotifications/UserNotifications.h> @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate> @end |
Register for push notification
Before registration check the version of iOS and then based on versions do the code. For iOS 7 code was different, fro iOS 8 & 9 code was different and again for iOS 10 code is different.
As per my opinion you have to set the deployment target to iOS 8 or iOS 9 and later. For this you can check the adoption ratio of iOS in the devices.
Define constant for version check :
1 |
#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) |
Add code in your did finish launching
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [self registerForRemoteNotifications]; return YES; } - (void)registerForRemoteNotifications { if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ if(!error){ [[UIApplication sharedApplication] registerForRemoteNotifications]; } }]; } else { // Code for old versions } } |
Handling delegate methods for UserNotifications
You will be surprise that notification displayed when application in foreground too in iOS 10. As we know that in old versions we display alert or something else which will be look like notification comes in foreground.
There are two delegate methods need to be handled :
1 2 3 4 5 6 7 8 9 10 11 |
//Called when a notification is delivered to a foreground app. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ NSLog(@"User Info : %@",notification.request.content.userInfo); completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); } //Called to let your app know which action was selected by the user for a given notification. -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{ NSLog(@"User Info : %@",response.notification.request.content.userInfo); completionHandler(); } |
Add Push Notifications Entitlements
Go to your project target’s Capabilities tab and add Push Notifications Entitlements.
If it’s available in your certificates then it will enable directly else configure your profile with the certificates and you can enable this capability by that.
All Done!
Happy Coding ?
I have added sample code of objective-c on github with iOS 8, 9 and 10 support of push notification.
I have also posted about Push Notifications in iOS 10 [Swift].
Apple simplified the screenshot submission process for iOS
Now it’s easier than ever to deliver your screenshots and app preview using iTunes Connect. Submit just one set of screenshots and one optional app preview per device family, and they will be used across device sizes and localizations.
If your app’s UI or behavior changes based on device size, or if you would like to include localized screenshots, you can use the new Media Manager to add custom screenshots. Learn more by watching What’s New in iTunes Connect from WWDC16.
iOS 10 New Frameworks
- CallKit
The CallKit framework (CallKit.framework) lets VoIP apps integrate with the iPhone UI and give users a great experience. Use this framework to let users view and answer incoming VoIP calls on the lock screen and manage contacts from VoIP calls in the Phone app’s Favorites and Recents views. - Intents
The Intents framework (Intents.framework) supports the handling of SiriKit interactions. - IntentsUI
The Intents UI framework (IntentsUI.framework) supports the creation of an Intents UI extension, which is an optional app extension that displays custom content in the Siri or Maps interfaces. - Messages
To develop an iMessage app, you use the APIs in the Messages framework (Messages.framework) and To create app extensions that interact with the Messages app, allowing users to send text, stickers, media files, and interactive messages. - Speech
Using the APIs in the Speech framework (Speech.framework), you can perform speech transcription of both real-time and recorded audio. - UserNotifications
User Notifications framework (UserNotifications.framework), which supports the delivery and handling of local and remote notifications. - UserNotificationsUI
User Notifications UI framework (UserNotificationsUI.framework) lets you customize the appearance of local and remote notifications when they appear on the user’s device. - VideoSubscriberAccount
Video Subscriber Account framework (VideoSubscriberAccount.framework) to help apps that support authenticated streaming or authenticated video on demand (also known as TV Everywhere) authenticate with their cable or satellite TV provider.
References :