2

このソフトウェアの組み合わせを単純なプッシュ通知に使用したいと思っています。

送受信は問題ではありません。

しかし、iOS から jQueryMobile アプリケーションに、PushNotification によって起動され、ホーム画面を表示するのではなく、通知関連の別の画面を表示するように伝えるにはどうすればよいでしょうか?

4

2 に答える 2

0

使用すると、アプリのデリゲート コードを変更し、アプリケーション プロビッシング プロファイルでプッシュを有効にすることができます #import "AppDelegate.h" #import "MainViewController.h"

    #import <Cordova/CDVPlugin.h>

    @implementation AppDelegate

    @synthesize window, viewController;

    - (id)init
    {
        /** If you need to do any extra app-specific initialization, you can do it here
         *  -jm
         **/
        NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

        [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

        self = [super init];
        return self;
    }

    #pragma mark UIApplicationDelegate implementation

    /**
     * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
     */
    - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
    {
        CGRect screenBounds = [[UIScreen mainScreen] bounds];

        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

        self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
        self.window.autoresizesSubviews = YES;

        self.viewController = [[[MainViewController alloc] init] autorelease];
        self.viewController.useSplashScreen = YES;

        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];

        return YES;
    }

    // this happens while we are running ( in the background, or from within our own app )
    // only valid if __TESTING__-Info.plist specifies a protocol to handle
    - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url
    {
        if (!url) {
            return NO;
        }

        // calls into javascript global function 'handleOpenURL'
        NSString* jsString = [NSString stringWithFormat:@"handleOpenURL(\"%@\");", url];
        [self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];

        // all plugins will get the notification, and their handlers will be called
        [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];

        return YES;
    }

    // repost the localnotification using the default NSNotificationCenter so multiple plugins may respond
    // ADD OUR NOTIFICATION CODE

    #pragma mark - Push notification Delegate Methods

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:      [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
        token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
        //NSLog(@"content---%@", token);
    }


    -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    {

        //flagPushConfirmation=[NSString stringWithFormat:@"startPush"];
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Error"
                  message:@"Device not Register for notification"
                 delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil];
        [message show];

    }

    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
       UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Notification"
          message:@"Recieve Notification" delegate:self cancelButtonTitle:@"cancel"otherButtonTitles:@"ok",nil];
        [message show];
    }


    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    {

        UIApplicationState state = [application applicationState];
        if (state == UIApplicationStateActive) {
            // WAS RUNNING
            NSLog(@"I was currently active");

            NSString *notCB = [notification.userInfo objectForKey:@"foreground"];
            NSString *notID = [notification.userInfo objectForKey:@"notificationId"];

            NSString * jsCallBack = [NSString
                                     stringWithFormat:@"%@(%@)", notCB,notID];


            [self.viewController.webView  stringByEvaluatingJavaScriptFromString:jsCallBack];

            application.applicationIconBadgeNumber = 0;
        }
        else {
            // WAS IN BG
            NSLog(@"I was in the background");

            NSString *notCB = [notification.userInfo objectForKey:@"background"];
            NSString *notID = [notification.userInfo objectForKey:@"notificationId"];

            NSString * jsCallBack = [NSString
                                     stringWithFormat:@"%@(%@)", notCB,notID];
            [self.viewController.webView stringByEvaluatingJavaScriptFromString:jsCallBack];

            application.applicationIconBadgeNumber = 0;
        }
    }
    - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
    {
        // iPhone doesn't support upside down by default, while the iPad does.  Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected).
        NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown);

        return supportedInterfaceOrientations;
    }
于 2013-11-30T13:17:10.560 に答える
0

Notificationオブジェクトには、アプリケーションが通知を介して起動された場合applicationLaunchNotificationに値を持つプロパティがあります。1

以下のメソッドは、アプリケーションの開始時に保留中の通知を照会します。

window.plugins.pushNotification.getPendingNotifications(function(notifications) {
     if(notifications.length > 0){
          var note = notifications[0];
          if(note.applicationLaunchNotification == "1"){
              // do the processing
          }
     }
});

詳細 - https://github.com/phonegap/phonegap-plugins/tree/master/iOS/PushNotification

于 2012-07-16T07:45:40.720 に答える