I have two apps written with Objective C. I have an IOS 8 jailbroken device. Can I get information from the view of another application?
Can I access self.view of the other app? I want to send a clicks command (touch up inside) to button in my other applications? Is it possible?
I have, ios 8, jailbreak device, xcode 6.3.
I'm sorry for my bad english.
no need for jailbrake.
here is something really quick you can try to open and click button in 2nd app.
Use URL schemes to open app from another app.
in the 2nd app in plist in URL types\item\URL Schemes\item0 add string say my2ndapp
to open 2nd app from your 1st app use:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"my2ndapp://somedata"]];
so now url: my2ndapp://somestring - will open your 2nd app and run method in its appdelegate:
(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
//do something with url if you need to, you can use it to tell yuor 2nd app do different things
openedFromURL=YES;//set bool flag, add this BOOL var in .h of appdelegate
return YES;
}
then in the same appdelegate in method
-(void)applicationDidBecomeActive:(UIApplication*)application{
if(!openedFromURL){return;}
//run method from viewcontroller you want, import it in .m and add it in .h of your appdelegate
MyViewController * myvc = [[MyViewController alloc]init];
[myvc myMethodHere];
openedFromURL=NO;//drop flag
}
you can go to your particular view or viewcontroller and run the method that is associated with your button touch up inside event
Similarly, you can make 2nd app interact with 1st one too.
Related
I have an iPad app in which I'm starting to support multiple windows / scenes. I have one main window type, let's say MainScene, and at least one secondary window type for opening specific types of content, say DetailScene.
I have not declared my scene types in Info.plist. I have implemented application:configurationForConnectingSceneSession:options: like this:
-(UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options
{
NSUserActivity *activity = options.userActivities.anyObject;
NSString *activityType = activity.activityType;
if ([activityType isEqualToString:#"detailType"])
return [DetailSceneDelegate makeSceneConfiguration];
return [MainSceneDelegate makeSceneConfiguration];
}
Say I perform these steps:
Launch app for the first time. I get a call to configurationForConnectingSceneSession, and the activity type is nil so it returns a MainScene.
Open a new window for some piece of content. That uses the detail scene activity type, so configurationForConnectingSceneSession returns a DetailScene. Creating the new scene looks like this:
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:#"detailType"];
activity.userInfo = #{#"content_id": #(contentRowId)};
[[UIApplication sharedApplication] requestSceneSessionActivation:nil userActivity:activity options:nil errorHandler:nil];
Suspend the app and open the app switcher. Discard (by flicking up) first the main window and then the detail window. The app is now killed.
Relaunch the app.
At this point I do not get a call to configurationForConnectingSceneSession. I get the detail scene back, restored from its user activity, with calls straight to DetailSceneDelegate.
My question: how do I control what scene gets restored in this situation? I want my main scene to come back.
Messages and Mail and Notes all do this. If you open Messages and drag a conversation out into a new window, you get a window for that conversation with a Done button in the corner that will dismiss the window. If you perform my steps above with Messages, you will relaunch to the full Messages view. Are they converting the detail view to a main view on the fly? Or is there a way to tell the system that the detail scene is secondary and should not be restored first, or that I should get asked what I want to restore via configurationForConnectingSceneSession? Or something else?
I cross-posted this to the Apple Developer forums and got an answer from a Framework Engineer. The answer is UISceneActivationConditions, set as a property on UIScene. Set the canActivateForTargetContentIdentifierPredicate to always return NO:
scene.activationConditions.canActivateForTargetContentIdentifierPredicate = [NSPredicate predicateWithValue:NO];
I do this in my implementation of scene:willConnectToSession:options: in my UIWindowSceneDelegate implementation.
As of current writing, on Xcode 13.2 and iOS 15.2 simulator, it works if the second launch (step 4 above) is via tapping the app icon, but not when it's via building and running in Xcode. I may file a feedback on this.
My app sends a request at startup and displays a brief message to users when it succeeds, by means of MTStatusBarOverlay. Unfortunately, my current implementation seems to run afoul of iOS 9's view life cycle paradigms. I get the message
Application windows are expected to have a root view controller at the end of application launch
and the app crashes. The app works fine on iOS 7 & 8.
From searching around online, it seems like this might occur when trying to add the message view to the view hierarchy before the root view controller is established for the app's UIWindow, but that doesn't seem to be the case here, see below.
Here is an excerpt of the UIApplicationDelegate implementation:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[...]
self.window.rootViewController = [[MyViewController alloc] init];
[...]
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[MyDataManager sendRequestWithCompletion:^{
// Displays a message with MTStatusBarOverlay
[self showSuccessOverlay];
}];
}
application:didFinishLaunchingWithOptions: is called before applicationDidBecomeActive: so it seems like there should never be an issue with rootViewController being established.
Why is this happening? What's different about iOS 9 that's causing the app to break?
MTStatusBarOverlay is a subclass of UIWindow, so instantiating one during app launch adds that UIWindow to the list that iOS checks for a populated rootViewController when launch completes.
I was able to work around the issue by instantiating and assigning a dummy controller before using the overlay, like so:
[MTStatusBarOverlay sharedInstance].rootViewController = [UIViewController new];
[[MTStatusBarOverlay sharedInstance] postMessage:#"Message"];
Am developing an IOS app. Where i need to make some images upload to server. Am using NSURLSession and uploadTaskWithRequest to do this. Every thing is working fine in normal way. My requirement user wants to store some post with more than 10 images in app using database SQLLite. And later show all the stored posts in UITableView with button for each UITableViewCell. When user tap on each button it should start uploading each POST to server. So I thought i should persist my UIViewController in AppDelegate so the process of uploading should not be killed when user go to another view controllers.
My Problem: When user close the app the process is in which UIViewController POST uploading is Stoping. So i would like to know how to keep my UIViewController live even in app go close or go into background.
Is there any better way to fulfill my requirement.
Here are some better ways!
Use a singleton. In my apps, I'll usually create a class called "DataHandler" that handles all of the NSURLSession/CoreData/etc stuff so all I have to do is
[DataHandler uploadImages:images];
and when I need the information back I'll call
self.tableData = [DataHandler lastUploadedImages];
This way I don't have to worry if my view controller is still alive.
Have the AppDelegate do the NSURLSession stuff. You already know the AppDelegate is persisted so why not just have that guy do it! Here is an example:
UIApplication *sharedApplication = [UIApplication sharedApplication];
AppDelegate *appDelegate = [sharedApplication delegate];
// this is the method you would add to your AppDelegate. Make sure to
// import your AppDelegate's header file so your ViewController can
// call the method.
[appDelegate uploadImages:images];
I have a sample code with a header and an implementation file and the two appDelegate files. I would like to add what the project does to my app. The first two files are a ViewController file, so I just need to drag it in, but the other two are AppDelegate, and I obviously can't have two app delegate. But in the case of this sample app the app delegate is used as a proper viewcontroller, because in the .m file of the UIViewController file, there is this code:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
Since the AppDelegate doesn't implement methods such as applicationWillBecomeActive:, how can I transform the file into a UIViewController file? What do I need to change in the code above to call the controller, instead of the Delegate (my AppDelegate will so remain untouched).
The code is on GitHub
This is what I have done (the code needs the Facebook API to be included). Go on the download tab and download Archive.zip and AppDelegate.zip: https://github.com/Alexmitico45/FacebookRequests/downloads
Basically the controller ContactFBSViewController is linked the a viewcontroller in the storyboard.
AppDelegate is the singleton that implement the protocol UIApplicationDelegate, because so you can't duplicate it, it must be unique.
You can create your own singletons to store the info available all over your app.
You can google "objective-c singleton" and get some good link to do it
I'm working on an iOS app and looking to see if it is possible to know when a user opens a URL (for example, user press a button and executes code like below)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt://1234567890"]]
telprompt: show an alert when it's called. But I want a way to detect if user press Ok button or Cancel button. I need execute some code in -(void)applicationDidEnterBackground:(UIApplication *)application depending which button was pressed. Any idea?
You could subclass UIApplication and over-ride openURL:
This will give you control and have you decide what to do.
Make sure to call super implementation though if you want to open the URL
EDIT
Here is an example
How to subclass UIApplication?