xcode5 - responding to appDelegate notification from beacon -
xcode5 - responding to appDelegate notification from beacon -
i experimenting app notifies users if on device same app willing connect them. set receiving beacon in app , location manager notification sent app delegate display. want have action happen if person receiving notification taps on ok button. here of code.
// set receiver beacon in beaconviewcontroller
nsuuid * uid2 = [[nsuuid alloc] initwithuuidstring:@"3b257014-2c29-40e0-8e1e-1d7a9e5d0964"]; self.beaconregion2 = [[clbeaconregion alloc] initwithproximityuuid:uid2 identifier:@"com.checkers.bluetooth"]; [self.beaconregion2 setnotifyentrystateondisplay:yes]; [self.beaconregion2 setnotifyonentry:yes]; [self.beaconregion2 setnotifyonexit:yes]; //send notification app delegate
-(void)locationmanager:(cllocationmanager *)manager didenterregion:(clregion *)region { // see if we've entered region. if ([region.identifier isequaltostring:@"com.checkers.bluetooth"]) { uilocalnotification * notification = [[uilocalnotification alloc] init]; notification.alertbody = @"want play checkers?"; [[uiapplication sharedapplication] presentlocalnotificationnow:notification]; } } //in appdelegate set notification
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.locationmanager = [[cllocationmanager alloc]init]; self.locationmanager.delegate= self; // override point customization after application launch. homecoming yes; } -(void)application:(uiapplication *)application didreceivelocalnotification:(uilocalnotification *)notification { alertview= [[uialertview alloc] initwithtitle:@"play game?" message:notification.alertbody delegate:null cancelbuttontitle:@"ok" otherbuttontitles:@"cancel", nil]; [alertview show]; if ([notification.alertbody isequaltostring:@"want play chess?"]) { messagestring = @"chess"; nslog(@"messagesting:%@",messagestring); }} //i next seek find out if "ok" button pressed
-(void) alertview:(uialertview *)alertview diddismisswithbuttonindex:(nsinteger)buttonindex{ if (buttonindex == 0) { if ([messagestring isequaltostring:@"chess"]) { messagestring3 = @"play chess"; } } } //finally in beaconviewcontroller want results of handed off can create action in view controller
appdelegate *appdelegate = (appdelegate *)[[uiapplication sharedapplication] delegate]; messagestring2 = appdelegate.messagestring3; nslog(@"messagesting2:%@",messagestring2); i notification , can recognize notification.alertbody cannot find out button beingness tapped or assign value messagestring3 tapping button on notification.
can help this.
so figured out. 2 things 1. created , synthesized uialertview reference 1 wanted. 2. if @ alertview has delegate set null , should set self.
once did these 2 things working great.
xcode5 ibeacon nsnotifications
Comments
Post a Comment