2

我很乐意将这种软件组合用于一些简单的推送通知。

发送和接收不是问题 - 做到了!

但是我如何告诉 iOS 之外的 jQueryMobile 应用程序它是由 PushNotification 启动的,并且不应该显示主屏幕,而是显示其他 - 通知相关 - 屏幕?

4

2 回答 2

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 回答
0

use can change you app deligate code and enable push in application pro-vising profile #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 回答