Notification Service Extension modifies the content of a remote notification before it's delivered to the user. For example if a remote notification contains an image URL, Notification Service Extension can be used to fetch the image and show it in the notification content.
But how can I access actual app code in Notification Service Extension? Let's say I have a DataAccess swift class in app code, can I access this class in Notification Service Extension?
Edit: Some folks suggested to add app code to service extension, which is not applicable in my situation.
Go to the classes that you want to use in your app project. On your File inspector your are gonna see the Target Membership of your class. Check the extension's name checkbox. Then you can reuse your code.
You can also add the classes you need in the Build Phases -> Compiled Sources in your notification service target. The result is the same.
The usual solution is to create a library/framework which includes your DataAccess class, and your app and the Notification Service Extension uses this library/framework.
Make sure you select Do not embed for your framework when adding to Notification Service Extension, and select Embed and sign when adding it to your app.
Related
I want to integrate Siri in my flutter app for iOS. When the user asks a particular question,
Siri must get the output from the app and execute a function in the app. How can I achieve this?
any help will be appreciated.
In order to achieve this you will need the following:
Create your intent definition file in XCode
Add the Intents extension target to your Xcode project
Configure the Flutter extension home widget
https://pub.dev/packages/home_widget
Add app groups capabilities to both your Runner target and the Intents target make sure to use the same group id
Initialize the App on the flutter side with the same group id
Save the data that your Siri intent would need using the home widget extension methods
Use the saved data reading from UserDefaults
There are some things to consider here:
Siri's intents are in a different Target because they can run in the background if needed, this is why you cannot have a direct communication line between the intent and flutter (Yet).
Instead what you will need to do is to save in memory some data your user might need when using Siri maybe a user id or API key, if you need to make some HTTP calls you will have to do it from Swift.
This is why we need the home widget extension since Home widgets also use a different target and This extension opens a communication channel using App groups and UserDefaults we could use the same communication channel to send data to our Siri Intent.
Just follow the configuration guide of the HomeWidget extension and add AppGroups capabilities to your runner Target and also to your Siri intent. make sure you use the same group ID in all of them including on the flutter side:
HomeWidget.setAppGroupId('YOUR_GROUP_ID');
Then you can use the extension methods to send and receive data between flutter and swift.
I’m creating an App ID for a Notification Service Extension
Do I need to add any capabilities to it?
Its only purpose is to download the image for the notification. I don’t think I need to.
Currently I'm able to build into my device without enabling any capabilities in Xcode. Although when I look into the provisioning profile that Xcode built itself, I see Keychain Sharing enabled.
I also saw this tutorial and the tutorial goes with enabling 'App Groups'.
While this other tutorial goes with enabling App Groups along with Push notification. I don't think I need App groups because I don't need to pass any values, just updating the notification is all I need.
I didn't find anything in the docs that mentions what's the correct approach. A friend told me he got his to to work without enabling anything, so I'm very confused.
Basically, you don't need any capability for notification service extension.
Several of my applications work without any capability.
One of them use app group. I need to enable it to share the log files of main application, then load it from notification service and push it to server side when receive a silent push.
Few of them need keychain sharing, so that I can get the key to secure communicate with server side from notification service.
As i have never created a framework or sdk please guide on how to create it .
Push notification features
1) Different type of push notification(text,custom,image) handling on receive of push notification
2) Whenever a user receive push notification a request will be going to server that the particular user have recieved the notification and hence will not send that notification again to same user.
i just want to know which will be the best possible of creating this .
I have read about cocoa touch framework and cocoa touch static library.
At the end of this i have to get into one file just like in android we create .aar and share .
So i have concluded to to create Cocoa static library and then share it. or there is better way to proceed
Thanks
Static library are the only option for hiding your private classes.
If you dont need to hide anything you can opt for framework and directly import it in any project.
1) Start the project
2) Put the file .a in your project in which you want to use
Please go through this link if you face any import errors.
https://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial
Hope it helps.
I need help on Action Extension, extension feature in iOS8. I am able to create a Action Extension target in my application and is able to see the extension in different Apps say Notes, Photos. Now, i am not able to call the appdelegate and other classes objects in the extension class.
So, how can i import Photos/notes and store it in my application?
You can't use the app delegate because it does not exist in an app extension. Extensions do not run as part of your app, they run independently of it. Moreover, [UIApplication sharedApplication] is specifically not available in app extensions, so the concept of an app delegate is not meaningful to app extensions.
As for how you can import photos and/or notes, that really depends on how your app works. Action extensions can receive data from the host app (Notes or Photos, as you mention) but how you add it to your app depends on your app's design. You get the data via NSExtensionItems, and process it however you need to process it.
Check this out. This might help you.
Appcoda Extension Tutorial
From WWDC 14 Sample Codes.
ImageInverter: Creating Action Extensions
Demonstrates how to use an Action extension with a view controller.
I can not use
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
in WatchKit Extension, I have error:
'sharedApplication()' is unavailable: Use view controller based solutions where appropriate instead.
Is there some alternative ?
The short answer is: No there isn't.
The long answer:
Please keep in mind that the extension is not executed on the watch but on your phone. So if you would call UIApplication.sharedApplication() it would return you the application of the extension on your phone, anyway! Everything you do inside your extension is stuff that manipulates the extension on your phone. The only exception from this are the WatchKit methods. And even they are basically calls that are converted into instructions that are send over bluetooth to tell the watch what to do. At no time you can write code that executes on the watch!
You have no control what so ever about what the watch does with the instructions you send to it. You are basically acting as a server talking to a client and you have no control over the client. You should send as little instructions as possible and once you send them, your task is done, the rest is up to the watch.
That being said, you should carefully plan your UI in a way that you do not need any calls that manipulate the event delivery. You should focus on simple 'if user taps x I do y' interaction.
Another thing to keep in mind is, that your extension can not communicate with your main iOS app. You can create a shared app group between your iOS app and your watch extension to share data between them, however you can not directly communicate with your app. If you want to use parts of your apps logic, extract the module in question into a framework (this has become very easy with Xcode 6) and use the framework in both, your app and your extension.