I want to send crash report to server, from any view controller.
I tried NSSetUncaughtExceptionHandler but it is implemented in delegate.
As I am creating library, so I want to send crash report from library.
You can use frameworks available
Crashlytics
Instabug
HockeyApp
Parse
Your "library" can be a class, which you can instantiate (e.g. as a singleton), or call class methods. Include the header file, and you can call it from anywhere.
If you instantiate it globally (e.g. as a singleton), then you can also have it handle delegate methods, such as those from NSURLSession.
You can even create your own protocol and delegate methods to bubble up events to the caller.
Related
I use a Firebase realtime database in an iOS app and I get a crash report through Firebase's crash reporting at [FIRDatabase assertUnfrozen] called from [FIRDatabase setPersistenceEnabled:]. (There's also a variation of these reports where the source is FIRDatabaseConfig rather than FIRDatabase)
In my app delegate's application:didFinishLaunchingWithOptions: method, I load the Firebase config from a file and then set persistence to enabled. For about 1 out of every 200 users this causes the crash with assertUnfrozen. Am I initializing Firebase in an incorrect way, or is there anyone with an idea about what's going wrong?
Calls to setPersistenceEnabled must be made before any other usage of FIRDatabase instance.This is reason for the crash, so check whether you are using FIRDatabase instance before calling setPersistenceEnabled.
In my case, I was using FIRDatabase instance in applicationDidEnterBackground and I had used setPersistenceEnabled in launchController.As soon as we open the app, before launchController is called, make the app go into background.Then, applicationDidEnterBackground gets called and FIRDatabase instance is used before calling setPersistenceEnabled.So, I removed firebase code from applicationDidEnterBackground and wrote it after setPersistenceEnabled is called.
I have an iOS project with three targers:
-Main App (parent)
-Today Extension (widget)
-Framework that holds some objects and methods, that are common to the parent app and the widget. Those members are being accessed from the app and the widget.
Both the app and the widget can send messages to the framework, but the framework cannot send messages to them. I cannot invoke app or widget method from the framework.
My problem is that: from the widget, I invoke some async method in the shared framework. Since the method is async, the widget does not know when the invoked method has finished its task.
I need the framework to notify the widget somehow when its method has finished, and trigger a response method in a widget class.
Is there a way to send message from the framework to the widget? I do not want to use the UserDefaults to share that information between targets.
I have been working on iOS framework (in Swift) which contains beacon functionality. I made it work except that I'm not sure how to handle scenario where I'm in foreground and I encounter multiple beacons in short duration.
If I want didReceive delegate method to show Alert for beacon while in foreground, and if I encounter many beacons it will not work nicely (alerts will display one over another). Is there some solution to queue notifications somehow?
Also I would like to know, if there is a way to make all that logic for receiving local notifications inside my framework?
I have to be able to support iOS-8.0 so I can't use Notification Center which is available from iOS-10.0
Can I create some class which would act like appdelegate (probably some class which would implement UIApplicationDelegate inside framework), is something like that possible?
I want to put as much code as I can inside framework itself so that it won't be too messy job for someone to include that framework with all functionality.
After some time I figured out a way to make this. I'm beginner in iOS with few months experience so I can't say if this solution is the best but it works for me.
I found a way to implement all push and local notification related delegate methods from framework. Basically if main application wants framework to take care of notifications without having to implement anything yourself, on runtime framework will dynamically implement certain UIApplicationDelegate methods for AppDelegate.swift class (or whatever is your AppDelegate class called).
I used object_getClass(UIApplication.shared.delegate!) to get the main class.
Then I used func class_addMethod(_ cls: AnyClass!, _ name: Selector!, _ imp: IMP!, _ types: UnsafePointer!) -> Bool
to implement delegate methods for push and local notifications from inside framework so now it comes down to write one or two lines to use framework entirely with working notifications and beacon location services instead of having to write a lots of code outside framework.
As for handling notifications in foreground mode I made that work by adding them to queue so that if more than one notification comes, and wants to be displayed in foreground regime, only one will be displayed by UIAlertController and the rest will be put in queue and sent again but with some small delay (I set fire date to be some value which I thought was appropriate in my case) after user makes an action regarding that first notification which was the only one presented.
These are just my ideas for the problems I had, if someone shows interest for these solutions I will write more details if needed. I will also gladly accept any criticism.
I have an iPhone app and added a WatchExtension. Now I managed to send a string to the Watch using the MMWormhole. In order to use the string I must call update() inside the WKInterfaceController from a method inside my UIViewController, so the iPhone application.
Is that possible?
I tried to do something like InterfaceController.update() but Xcode complained that it does not know the variable InterfaceController.
Thanks in advance :)
The iPhone App and Watch Extension are TWO seperate process, although they are stored in ONE bundle, so you can not call the method of other process in runtime.
In WatchKit:
If you want to share code, use Framework.
If you want to share data, use App Group.
If you want to use notification, use Inter-Process Communication(In iOS, It's Darwin Notification, and MMWormhole use this feature).
I think you want to let the Watch update its interface when iPhone app do something, you can do like this:
send a message to Watch Extension.
Watch Extension receive that message.
In the message handler, update interface.
In my option, the iPhone App and Watch Extension can be seen as a kind of C/S architecture, iPhone App is Server and Watch Extension is Client, maybe this metaphor is easier to understand.
I want to build a static library that catches incoming push notifications and uses the json objects outside the "aps" namespace. Is there any way to do this without changing the application:didReceiveRemoteNotification: method in the AppDelegate but by simply adding and using the static library?
Thanks in advance!
No, there isn't a way to do what you are asking (that I know of). First, you could do a class extension or category, but both would require the user to import them in the app delegate. Also, with that you could 'override' the method, but it wouldn't allow the user to 'use' that method in their app delegate (if they also wanted to perform some logic in the didReceiveRemoteNotification method).