Objective-C code for iOS QuickAction - ios

I've an iOS app with a Tab Bar Controller and five ViewControllers written in Objective-C.
Now, I declared QuickActions in Info.plist file.
But cause I'm new at coding and there are only Swift codes to find in the internet I don't know how to do it.
Can anyone provide the code snippet for AppDelegate.m in Objective-C to open an specific ViewController?
Thank you for help!
Greetings,
David.

if your application is launched fresh...then its launchOptions will contain shortcut item pressed which you can access using key UIApplicationLaunchOptionsShortcutItemKey.Find the type UIApplicationShortcutItem to perform action accordingly.
If your application is in background and your user selected shortcut item
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler
will be called.As you can see you get pressed shortcut item directly you can get type of pressed item and perform action accordingly.Hope it helps :)
Edit
You can check out https://github.com/dakeshi/3D_Touch_HomeQuickAction this will help you alot only difference is he has used dynamic quick actions.And one note about quick actions (both dynamic and static) is that unless you launch your app at least once quick options won't show up on 3D touch.

Related

UNNotificationContentExtension not displaying

I'm trying to make a custom notification alert. I added my extension target and changed the UNNotificationExtensionCategory value to 'drawing'.
In my push notification I added a "category" : "drawing" element to the aps block. The didReceive(_:) method from that extension is never getting called though. What did I forget to do?
You seem to have done whats needed. I too had similar problem of not seeing the custom notification screen.
However, whats not mentioned in the documents of UNNotificationContentExtension is that the custom screen appears only when you do a 3D touch on the notification alert. I tried to do a 3D touch and the custom screen appeared. Please check.
First check that the extension category is set appropriately in the extension info.plist file to match what is being sent in the aps block of your push notification
Second check that the deployment target for the extension is <= to the iOS version of the device you're trying to run on.
Have u added this in your target's info.plist file instead of ACTIONABLE add drawing
I had similar issue, it was just that in the plist I made my UNNotificationExtensionCategory to be an Array and I wasn't adding them correctly.
Incorrect:
It shouldn't come next to UNNotificationExtensionCategory ie it shouldn't be a field of NSExtensionAttributes
Correct:
It should be a field of UNNotificationExtensionCategory
Apparently to learn how to use the plist you need at least 25 years of experience :)
This method is only called once you force touch into the notification.
If you are monitoring this through LLDB, it runs as a separate process. Make sure you're building your extension target in order to access these methods and the logs from LLDB.
Lastly, if you are like me, and you have discarded the storyboard, then you need to specify the principal class in your extensions Info.plist. This class must be your main view controller including the target namespace. For example, if your extension is MyNotificationExtension then you would set NSExtension > NSPrincipalClass to MyNotificationExtension.MyNotificationExtensionViewController.

Removing unnecessary titles and icons at the top of iOS Simulators

I'm new to iOS and my question will seem little bit confusing to you but it make sense I'm working on a project where I have to use a custom NavigationBar while I was working on that I saw these icons and title at the top
and as the requirement of my project I need a Bar like this
and you can see the word slightly overriding my button (the red bar is not a part of my button). so my question is, is there any way we can remove these buttons from our simulator because I noticed when i click on the back button sometimes it'll not work due the fact I was clicking on the that "Carrier" title. Soo is there anyone who knows something about it and please don't suggest me to resize the button or something like that it's not my point if you understand.
As Nobody have Answered it yet let me tell you the answer that I find working:-
To hide status bar in iOS7 you need 2 lines of code
in application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions write
[[UIApplication sharedApplication] setStatusBarHidden:YES];
in info.plist add this
View-Controller Based Status Bar Appearance = NO

Is this a good way to add protocols to a class I'm hooking in?

I'm trying to write a test tweak for iOS 8.3 using Theos.
This tweak will show a UIAlertView with two choices when the user taps on an application's icon.
I want to distinguish between the buttons, and to do so I need to add the UIAlertViewDelegate.
Following this example written by DHowett, I've adapted his code to run under iOS 8.3.
The code compiles and loads fine but no action is triggered when I tap on any icon.
If I simply hook into SBApplicationIcon with the correct method, action is triggered but this way I'm not able to distinguish button press.
Is this still a good way to add protocols?
You can cast the class you're hooking into to id<ProtocolName> when setting the delegate.
For instance, in your case it would be something like:
[alert setDelegate: (id<UIAlertViewDelegate>) self];

WatchKit reloadRootControllersWithNames causing error, with pageController or after push/pop

I have a basic watchkit app that loads a page based navigation of 3 interface controllers. This works well, but I'd then like to trigger an action to remove the page-control and essentially revert back to the original InterfaceController that was present when the app first loads.
// load page based control, with 3 views. this works ok
[WKInterfaceController reloadRootControllersWithNames:#[#"pageController1",#"pageController2",#"pageController3"]
contexts:#[#"data1",#"data2",#"data3"]];
// attempt to reload original interface controller, identified by storyboard id
[WKInterfaceController reloadRootControllersWithNames:#[#"myInterfaceController"] contexts:#[#{}]];
The page based navigation remove, the original navigation loads after a short spinner. However it fails to function correctly and original Actions result in this error.
Extension[6766:123665] *********** ERROR
-[SPRemoteInterface _interfaceControllerClientIDForControllerID:] clientIdentifier for interfaceControllerID:(null) not found
Is there a better way to cleanly reload the original InterfaceController?
EDIT, 2/19
It seems there are some other actions that are causing this error too. For instance, if segue to a second InterfaceController and then popController to get back, the error often appears. It is always related to a secondary call to this function.
[WKInterfaceController reloadRootControllersWithNames: contexts:]
EDIT2, 3/18
As previously mentioned, this is reproducible 100% of the time by doing the seguePush, the popController, then attempting to reloadRootControllersWithNames.
If the seguePush/popController is not done beforehand, then the reloadRootControllersWithNames will work fine.
This situation seems to be in addition to the multi->single-multi instance of this bug.
This is actually not a bug because according to Apple:
You cannot combine hierarchical and page-based interface styles. At design time, you must choose the style that best suits your app’s content and design for that style.
So unfortunately, we can't mix Hierarchical and Page-based navigation patterns within the same Watch app.
Just one of many limitations we have to deal with when developing apps for  Watch
This is a bug in WatchKit in Xcode 6.2 Beta 5. Please dupe the following radar on Apple's Bug Reporting System to help raise the priority to get this fixed.
In the meantime, a workaround that I've found can be found on the dev forums. What you can do is add a dummy interface controller to any single interface controller page set so you always have two. This will fix the error until Apple get's the bug fixed (hopefully in Beta 6). Please dupe!
I was able to solve my instance of this problem by not using popController on a pushed view controller. Instead I use a reloadRootControllersWithNames in place of the popController.
How this allows both push and paging, via an example:
Push a view controller
reloadRootControllersWithNames to return to the original controller. (The transition is not quite as animated, but is sufficient)
Create page based view controller.
reloadRootControllersWithNames to return to the original controller
Repeat 1 or 3 as needed.
This eliminates the error at the cost of non-animated popControllers, and allows partial pushing and paging. It would not allow more complex push navigation though.
There may be a better method of navigating to a sub interface controller without a push call, but I'm not aware of it on the watch yet.
None or the answers above worked for me. This problem began when I changed the icon names for the app and the watch app name. I solved it like this:
1) Click on your Watch app Target > Capabilities > make sure app Group
is in ON.
2) Make sure the App Group is selected.
3) Clic on the circled arrow Refresh icon (this will apparently just
refresh this thing if you already had it)
4-Repeat steps 1-3, but for your Watch App EXTENSION target too.
5-Click on the Scheme button (on the right side of the STOP button),
and clic on Edit Schemes.
6-Click Run > Info 7-In executable select your target (Actually it
should already be selecting but opening this window seems to
refresh the option, and wipe the error)
Apparently all these things above are not updated automatically when you change the icon name (Target names) and you have to go to those menus and open them to refresh them manually. Shame on Apple perhaps?

Change the view controller app launches with when button is clicked - Xcode

I'm attempting to create an introduction to my iOS app. So I've created a few view controllers that are shown in the beginning of the app. On the last introduction view controller there is a button which brings you to "the actual app".
How do I make it so when that button is clicked the app launches with a different view controller.
If someone could walk me through the steps and be very detailed I would appreciate it as I'm a beginner iOS developer.
One option is to store whether "view intro" is set to true/false & set this value in NSUserDefaults. Check that value when the app starts & put an if/else to load the appropriate VC. You might want to make the button "skip" intro entirely & set this value. People generally get annoyed w/long intros & want to use your app. See this answer about NSUserDefaults.
I am assuming you are creating an "app tutorial" type of introduction. Also assuming that you only want this to occur the first time the user uses the app, then go directly to the app every other time.
I would store a didWatchTutorial BOOL value in the NSUserDefaults.
This would also need to include an if/else statement in the opening view controller of your app, which controls (based on this BOOL value) if the user should be shown the tutorial:
if (didWatchTutorial) {
//GO STRAIGHT TO APP
} else {
//SHOW TUTORIAL
}

Resources